Ajax.BeginForm does not raise "submit" event in IE 7 / 8
In ASP.NET MVC 3, I've declared an ajax form like this:
@using (Ajax.BeginForm("SaveRegistrationConfirmationRequest", null, new AjaxOptions { UpdateTargetId = "verify-email-result", HttpMethod = "Post" }, new { id = "request-form" }))
and I'm using jQuery to bind to the "submit" event (the alert
is just fo开发者_开发问答r testing):
$("#request-form").submit(function () {
alert("submit");
if (!$("#agree-checkbox").is(":checked")) {
$("#agree-dialog").dialog("open");
return false;
}
});
In Chrome and Firefox on Windows, the event handler is called and I see the alert. In IE 7 and 8, I don't see the alert and the form is submitted.
If I change the code to use a non-ajax form, then the handler is called in IE:
@using (Html.BeginForm("SaveRegistrationConfirmationRequest", "Account", FormMethod.Post, new { id = "request-form" }))
What do I need to do to get this working with an ajax form in IE? Any help would be appreciated!
I ended up using the ajaxSend event:
$("#request-form").ajaxSend(function (evt, request, settings) {
if (!$("#agree-checkbox").is(":checked")) {
request.abort();
$("#agree-validation").addClass("field-validation-error");
$("#agree-validation").removeClass("field-validation-valid");
}
});
This works in IE 7 and 8, Firefox, and Chrome.
精彩评论