views:

117

answers:

2

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 view) 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 help is appreciated.

A: 

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.

ZippyV
A: 

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.

Dustin Laine