0

using asp.net mvc2, Data Annotations, MicrosoftAjax.js,MicrosoftMvcValidation.js, jquery for ajax

I have contact form and i am using Data Annotations for the ContactFormModel.
I add this line <% Html.EnableClientValidation(); %> to top of the form.

When i click the submit button client validation works perfectly. Now i have changed my mind and want to post the form with jQuery.Ajax.

This time i want to accomplish this.

  1. Click submit button.
  2. MicrosoftMVCValidation does the client validation and renders the errors on the clientside.
  3. If Model is valid i meant if the validation passed i want my jQuery ajax to get involved.

But when i clicked the submit button both ajax post and mvc client validation works. How can i get the things in right order.

1.Mvc Client validation
2. Then jQuery.Ajax Post.

    1 Answer 1

    1
     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 ... } 

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.