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


I don't know if MicrosoftMvcValidation provides such a function, but using jQuery you can check if any of the form fields contain errors:



var isValid = $('#formId .input-validation-error').length > 0;

      

+7


source


            // 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


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


var pageValid = Page_ClientValidate();

      

This is a built-in .NET function, just run it and you will know if all validators passed. You can also use it inside the onClientClick (return func ()) form validation function. and add more of your JS manipulations.

0


source







All Articles