In my asp mvc application I use 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 search for some standard flag which indicates client side validation status. Does anybody know about it? Does it exist?
Asked
Active
Viewed 1,848 times
4 Answers
7
I don't know if MicrosoftMvcValidation exposes such function but using jQuery you might check if any of the form fields contain errors:
var isValid = $('#formId .input-validation-error').length > 0;

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
-
Yep, I know this and actually now I use jQuery to check validation status. But I'm sure there are some standard things to do this. But thank you anyway =) – Igor V Savchenko Apr 13 '10 at 07:05
-
2I think the variable should read : "isInvalid" and not "isValid". – user2173353 Jun 15 '15 at 08:28
0
If you are using the jquery validate unobtrusive, you should use that:
$(function () {
$('#formid').submit(function () {
if (!$(this).valid()) {
$('#validation-summary').show();
}
});
});
From: How to fire jQuery function only if form is valid - Darin Dimitrov

Community
- 1
- 1

Ygor Thomaz
- 507
- 5
- 14
0
var pageValid = Page_ClientValidate();
This is a built in function by .NET, just run it and you will know if all validators did pass. You can use it as well inside a Form Check function onClientClick (return func()). and add more of your JS manipulation.

DeleteMyAccount
- 11
- 9
0
// 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
...
}

Robert Tanenbaum
- 419
- 4
- 4