ASP.NET MVC 3: Required steps for unobtrusive client-side validation of dynamic/AJAX content

爷,独闯天下 提交于 2019-11-27 10:19:59
Kaleb Pederson

At this point I believe the following is a complete set of requirements:

  1. Create a form with Html.BeginForm
  2. Turn on ClientValidationEnabled
  3. Turn on UnobtrusiveJavaScriptEnabled
  4. Set appropriate validation attributes on the model's properties (not fields)
  5. If the Html Helpers being used to create the form elements are not on the same form as the Html.BeginForm call, use a relevant workaround (see workaround 1 and workaround 2)
  6. Include jquery, jquery.validate.js, and jquery.validate.unobtrusive.js files, in that order
  7. Verify that the unobtrusive validation attributes are present in the HTML
  8. If using custom validators:
    • ensure that they are added to jQuery.validator.unobtrusive.adapters
    • ensure that they are added to the jQuery validation plugin by calling jQuery.validator.addMethod.
    • ensure that the above happen before $(document).ready() as at that point it's too late
  9. Call jQuery.validator.unobtrusive.parse or jQuery.validator.unobtrusive.parseElement on elements added dynamically after the initial page load.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!