Data Annotations Validation + jQuery.Ajax Post

允我心安 提交于 2019-12-24 09:57:45

问题


This question was asked but was not answered.

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.

  • Click submit button.
  • MicrosoftMVCValidation does the client validation and renders the errors on the clientside.
  • 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:


I found the solution.

Use these JS :

jquery-1.4.2.min.js
jquery.validate.js    
MicrosoftAjax.debug.js
MicrosoftMvcAjax.debug.js    
MicrosoftMvcJQueryValidation.js


来源:https://stackoverflow.com/questions/4679559/data-annotations-validation-jquery-ajax-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!