Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8147205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:16:20+00:00 2026-06-06T14:16:20+00:00

Here is a bizarre problem. I call an ActionResult in my controller from jQuery

  • 0

Here is a bizarre problem.
I call an ActionResult in my controller from jQuery on a view.

Here is the jQuery

$(document).ready(function () {
    $('.addNoteLink').button();

    $('.addNoteLink').click(function () {
        var cid = $('#CaseID').val();
        var notetext = $('#NoteText').val();
        var url = "/Cases/AddNoteText";
        $.ajax({
        type: "POST",
        url: url,
        data: { id: cid, note: $('#NoteText').val() }
            });
    });
});

Here is the controller method:

public ActionResult AddNoteText(int id, string note)
        {
        try
            {
            if (ModelState.IsValid)
                {
                CaseNotes notes = new CaseNotes
                {
                    CasesID = id,
                    NoteDate = DateTime.Now,
                    NoteText = note
                };
                db.CaseNotes.Add(notes);
                db.SaveChanges();
                }

            }
        catch 
            {

            }
        return RedirectToAction("Edit", id);
        }

Here is the html related to the jQuery:

<div class="editor-label">
                    @Html.Label("Enter notes here and click Add Note Text")
                </div>
                <div class="textarea-field">
                    <input id = "NoteText" type="text" />
                </div>        
                @Html.ActionLink("Add Note Text", "AddNoteText", new { id = Model.CasesID }, new { @class = "addNoteLink" })

When the jQuery calls this method, if I follow with a breakpoint, the parameters are pass correctly, the ModelState is valid, it goes into the notes entity and assigns values etc. When the breakpoint hits db.CasesNotes.Add(notes) the breakpoint returns to the top of the function and goes down again until it hit the notes entity then jumps to db.SaveChanges()
then returns to the top AGAIN, goes thru the method and errors out because the parameters have been cleared by that point. The original record gets inserted though.

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:16:22+00:00Added an answer on June 6, 2026 at 2:16 pm

    If you subscribe on an anchor with jQuery click the browser will still execute the default action (e.g follow the link) when you click on the link. That’s why your action called twice.

    You need call to call the preventDefault() on the event object to cancel the browser default behavior:

    $('.addNoteLink').click(function (event) {
        event.preventDefault();
    
        var cid = $('#CaseID').val();
        var notetext = $('#NoteText').val();
        var url = "/Cases/AddNoteText";
        $.ajax({
        type: "POST",
        url: url,
        data: { id: cid, note: $('#NoteText').val() }
            });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a truly bizarre problem with my code here. It works (seemingly)
Hello I have a bizarre problem with sprintf . Here's my code: void draw_number(int
Here is the problem that I am trying to solve. I have two folders
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
I have this bizarre problem. I'm making a checklist program with XCode and I'm
I have what I think is a bizarre problem. With the same mapping to
I'm pretty certain I'm missing something really obvious here but this seems quite bizarre.
I have a bizarre problem using Qt Creator that I can't reproduce with Visual
OK, very bizarre issue here, can't seem to find much on it searching through
This is a follow on question to my Heroku / Clojure problem here .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.