I have a simple form created using Ajax.BeginForm
:
<% using (Ajax.BeginForm("Update", "Description", new { id = Model.Id },
new AjaxOptions
{
UpdateTargetId = "DescriptionDiv",
HttpMethod = "post"
},new {id ='AjaxForm' })) {%>
Description:
<%= Html.TextBox("Description", Model.Description) %><br />
<input type="submit" value="save" />
<% }%>
The controller is wired up and returns a partial view that updates the DescriptionDiv
. And it all works neatly.
Now I would like to be able to submit this form without having the submit button (via a clik on a link or on an image or whatever). Unfortunately this little jQuery snippet does not do the job:
$('form#AjaxForm').submit();
It does submit the form, but does (I suppose not surprisingly) a regular post-back and not an Ajax one.
For the sake of simplicity the above jQuery is wired up like this:
<a href="#" onclick="$('form#AjaxForm').submit(); return false;">submit</a>
The form's onsubmit is using the Sys.Mvc.AsyncForm.handleSubmit() but the jQuery submit seems to be bypassing this.
PS. I am looking for a solution in this particular approach. I know how to achieve the same using a normal form and posting it using AJAX+jQuery. I am interested in this particular solution though.