I'm new to ASP.NET MVC; something I'm having trouble with is getting data from a jqueryUI dialog form and passing it to the controller so that I can, for instance, save form input to a database.
The method in my controller for handling this doesn't get called for some reason, despite the fact that it seems to be referenced correctly in the jquery code. Here is what I have in the view (I've obviously omitted most of the code, just putting the relevant parts here for readability):
<a href="#" id="dialog_link">Open Dialog Box</a>
<div id="dialog" title="MakeSomeSampleNote">
<form id="testform" method="post">
<input id="tbx_casenote" name="tbx_casenote" type="text" style="height:50px; width:200px;" />
</form>
</div>
$("#dialog").dialog({
autoOpen: false,
resizable: true,
height: 210,
width: 510,
modal: true,
buttons: {
"Ok": function () {
var noteval = $("#tbx-casenote").val();
$.ajax({
type: "POST",
url: "@Url.Action("NoteController/SaveNote")",
data: { content: tbx_casenote_val },
cache: false,
dataType: "json",
success: function (data) {
$("#dialog").dialog("close");
}
});
},
"Cancel": function () {
$(this).dialog("close");
}}
});
$('dialog_link').click(function () {
$('#dialog').dialog('open');
return false;
});
Here is the method I'm using in the controller; when debugging, this method never gets hit after I test the dialog form and click the "Ok" button:
[HttpPost]
public JsonResult SaveNote(string NoteText)
{
//code to save this note to database - not relevant to question
return Json(new { success = true });
}
Thanks.
autoOpen: falsewhere are you opening/showing the dialog? Also you seem to be using sometbx_casenotejavascript variable in your AJAX call which is not clear where is defined.