I have this form:
@using (Html.BeginForm("Update", "MyController", FormMethod.Post, new { id = "frmEdit" })) {
<input type="text" id="Title" value="Adam" />
}
Here is the jquery:
$(function () {
$('#frmEdit').submit(function () {
//read form values
//verify req fields
if (isValid) {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
beforeSend: SpinWheel(l),
success: function (result) {
if (result.s == 'OK') {
alert("Success Updated");
}
else {
Alert("Sorry! Update failed.");
}
},
error: function (xhr, status, error) { alert('Error');}
});
}
return false;
});
});
Controller:
public ActionResult Update(FormCollection album)
{
return Json(new { s = "OK" });
}
The form has a modal inside it. When I click a link in parent page, the modal is launched.
In the modal I have the form with a submit button.
Try adding a call to
preventDefault()on theeventpassed in:bad copy/paste?
alert(Error');If so, this could be the reason it wasn’t hitting the
return false;at the end of yoursubmitevent