I am using a dialog box as such:
<div id="dialog" title="Edit Information" style="overflow: hidden;">
</div>
$('#dialog').load("@Url.Action("EditInfo")",
function(response, status, xhr) {
$('#dialog').dialog('open');
});
Once the user user clicks on submit in the dialog box I got to httppost as such
[HttpPost]
public ActionResult EditInfo(MicroInfo model)
{
if (ModelState.IsValid)
{
lbService.EditMicroInfoData(model);
return View(model); // success
}
return View(model); // problem
}
When it goes to
return View(model) // success
, it does not goes not open in the dialog box but in a normal page. I like to open it back in the dialog box so the user can close the dialog box.
I am wondering if I should do this in a
$.ajax( ....
call
You could use an
Ajax.BeginForminside the partial that you are loading. So put the contents that you want to be loaded in the dialog inside a partial and also have yourHttpPostcontroller action return this same partial view instead of returning an entire view.Don’t forget to include the
jquery.unobtrusive-ajax.jsscript to your page if you want theAjax.BeginFormform to work.As an alternative to using Ajax.BeginForm you could still use a normal Html.BeginForm and manually AJAXify it: