UPDATE: I've created a new MVC 3 project with Razor HTML 5, then I've updated the project with NuGet at JQuery 1.6 and the validation plugin doesn't work any more, it does a post back every time and returns the error message from server. I think the validation plugin is broken with JQuery 1.6
I have a MVC 3 app that uses Jquery UI dialog (loaded from a partial view that contains a form) in order to submit information over ajax to the server. I want to trigger the validation of my form on the client side before I do the ajax post. On Firefox and IE9 works fine, in IE7 & IE8 the form.validate() always returns true.
Here is the js code attached to my submit button:
var wizard = $("#wizard"); //div that holds the modal dialog
var myform = $("#wizard form");
var submitFunction = function (e) {
e.preventDefault(); //no postback
myform.validate();
if (myform.valid()) {
$(this).attr("disabled", "disabled");
submited = true;
$.post(
"SuperAdmin/CreateEditController",
$(this).serialize(),
function (data) {
if (data.Success) {
wizard.dialog('destroy');
}
else {
wizard.html(data.Html);
}
},
"json"
); //end json post
}
};
myform.submit(submitFunction);
I am using the following includes:
<script src="@Url.Content("~/Scripts/jquery-1.6.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
The JQuery Validation plugin was upgraded with NuGet at version 1.8.0 and JQuery library to 1.6.
Update: I've tested the code generated with scaffolding default template and it does the same thing, no client side validation. Maybe JQuery 1.6 is not compatible with the Razor scaffolding template ??
Jquery Validate does not currently work with jQuery 1.6 in IE6, IE7, and IE8.
https://github.com/jzaefferer/jquery-validation/issues/105
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With