Is there any "valid" flag for ASP.NET MVC client side validation?
In my asp mvc app I am using standard client side validation (DataAnnotations + MicrosoftAjax.js + MicrosoftMvcValidation.js). I need to show some popup message (jGrowl) after successful / unsuccessful client side validation (so I can't use ModelState.IsValid). So I'm looking for some standard flag that indicates the client side validation status. Does anyone know about this? He exists?
+2
source to share
4 answers
// Now get the validation context and call the validate() method
var myForm = $("#MainForm");
var formContext = myForm[0]['__MVC_FormValidation'];
var errors;
if (formContext) {
// validate the form
errors = formContext.validate("submit");
}
if (!formContext || errors.length == 0) {
// no errors so submit to server
...
} else {
// found errors
...
}
0
source to share
If you are using jquery's validate unobtrusive you should use this:
$(function () {
$('#formid').submit(function () {
if (!$(this).valid()) {
$('#validation-summary').show();
}
});
});
From: How to run a jQuery function only if the form is valid - Darin Dimitrov
0
source to share