I am building a site where I am calling a partial view within a jquery ui dialog box. Within the partial view there is a 'save' button that commits the data on the form to the database. Currently it redirects to a different view. I would like it to instead close the dialog box. I am unable to get it to properly call the function to close the dialog box.
Here is my code:
In the View:
<script type="text/javascript">
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$(".diagSave").on("click", function (e) {
e.preventDefault();
$("<div></div>")
.dialog({
title: $(this).attr("data-dialog-title"),
modal: true,
width: 1000,
success: function () {
$('#diagSave').dialog('close');
}
})
.load(this.href);
})
});
</script>
In the Controller:
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
Can someone please help point out how I can accomplish this?
An alternative would be to handle the save click in jquery, use .serialize to send the form collection to your controller, then close the dialog.