2

I have a view with a form that uses the unobtrusive client side validation in asp.net mvc 3 to validate the form fields.

I also have a custom jquery script to submit the form via ajax

$(document).ready(function () {
    $('#Submit').click(function (event) {

        /* collect form input values as json*/
        /* post the json data via ajax */

        event.preventDefault();
        event.stopPropagation();
    });
});

My question is how can I change the order of the event handlers so that the asp.net mvc 3 client side validation gets called before my ajax form post handler so that the asp.net mvc handler can prevent my handler from getting called if there are any validation errors.

The problem I am having is that the asp.net mvc 3 unobtrusive javascript validation event handler is not triggered before my event handler.

By disabling the code at the end of my script that prevents further event propegation, I can see that the asp.net mvc 3 client side validation is indeed getting triggered after my handler is executed.

1 Answer 1

4

You can call the method:

$('form').valid()

inside your event. Maybe this posts helps:

Sign up to request clarification or add additional context in comments.

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.