开发者

ASP.NET MVC Dialog Stumped

I am using jQuery's UI dialog to open a basic form. I want to submit that form and close the dialog. I am having trouble.

The parent window opens the dialog (which contains a partial vi开发者_高级运维ew) from click and form is submitted, they the browser opens the partial view in the browser. I want it to do the form work and close the dialog.

Is there a way to do this VIA Ajax.SubmitForm or some other method.


You need to capture the onsubmit event of the form, send the form via Ajax, close the dialog and then Return False to prevent the browser from submitting the form again and doing a full page postback.


I found an ideal solution and can't believe that I couldn't solve it earlier. Simply use Ajax.BeginForm using the OnSuccess function of the AjaxOptions.

<% using (Ajax.BeginForm("Action", "Controller", new AjaxOptions { OnSuccess = "CloseDialog" })) { %>
    <%= Html.Hidden("ID", ViewData["ID"]) %>
    <input type="submit" value="Submit" />
<% } %>

function CloseDialog() {
    $("#ImageCropModal").dialog("close");
}

This posts to the form without re-rendering the view. The I can close the dialog manually, after form post is successful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜