I have a jquery modal form with MVC 3, i got to post the data back to my controller but cannot get the dialog to close AFTER THE FORM IS SUBMITTED here is my form
@using (Ajax.BeginForm("CreateNewmODALs", "Finance",
new AjaxOpti开发者_开发技巧ons
{
UpdateTargetId = "my-modal-dialog",
OnBegin = "Dialogs.CreateEvent.Updating()",
OnSuccess = "Dialogs.CreateEvent.Update({ title:'Select Friends' })"
},
new
{
@class = "contactform"
}
))
{
@Html.ValidationSummary(true)
<p>
<input type="submit" value="Create New mODAL" class="demo-button ui-state-default ui-corner-all" />
</p>
Here is my Action link that invokes the form into modal
@Ajax.ActionLink(
"Open New mODAL",
"ACTION",
"CONTROLLER",
null,
new AjaxOptions
{
UpdateTargetId = "my-modal-dialog",
OnBegin = "Dialogs.CreateEvent.Opening({id: 'my-modal-dialog'})",
OnSuccess = "Dialogs.CreateEvent.Open({title: 'Create Event'})"
},
new
{
@class = ""
}
)
Here is my controllers
public ActionResult CreateNewmODAL()
{
return PartialView("../PartialViews/Finance/Modal/NewmODAL", mODALViewModel);
}
//
// POST: /Finance/Create
[HttpPost]
public void CreateNewmODAL(mODALContent mODALViewModel)
{
try
{
// TODO: Add insert logic here
//return RedirectToAction("Index","Home");
}
catch
{
//return View();
}
}
When you return from the Controller you get the control to the OnSuccess,OnError and finally OnComplete javascript methods.
On these javascript functions you need to explicitly close the dialog box.
eg
<script type="text/javascript">
function OnSuccess() {
alert('Close the dialog');
}
</script>
@using (Ajax.BeginForm("CreateNewmODALs", "Finance",
new AjaxOptions
{
UpdateTargetId = "my-modal-dialog",
OnSuccess ="OnSuccess" }
,
new { id = "my-modal-dialog" }))
{
...
}
精彩评论