1

I m using MVC2.0, DataAnnotation for Client side Validation.

my problem is how to get Client Side Validation result like whether form validation returns TRUE or FALSE on Click of Submit button in MVC2.0.

My scenario is like, I want to open a popup window in new Tab on click of Submit button using JQuery. But if Validation is false then it should not open the popup window.

Thanks in Advance.

2 Answers 2

2

Im using the builtin javascript validation library jquery.validate.js with my models and to check whether a form is valid based on the Model rules I do the following to validate on the client:

var FormID = $("#FormID");
$(FormID).submit(function(e) {
    if (FormID.valid()) {
        alert("Form is valid");
    }
    else {
        alert("Form is invalid");
    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

Finally i got the solution of my problem.

        function doPost(form) {
            var myForm = $("#form0");
            var formContext = myForm[0]['__MVC_FormValidation'];
            var errors;
            if (formContext) {
                errors = formContext.validate("submit");
            }
            if (!formContext || errors.length == 0) {
                //PUT UR CUSTOME JS CODE HERE
            }            
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.