ASP。NET MVC 3:动态/AJAX内容的客户端验证所需的步骤

时间:2021-12-11 16:36:10

What are the complete set of Steps Required for client-side unobtrusive validation to work for dynamically inserted form fields?

对于动态插入的表单字段,客户端不引人注目的验证所需的完整步骤集是什么?

Relevant SO posts

ASP.NET MVC 3 unobtrusive client-side validation with dynamic content - He needed the unobtrusive validation attributes to show up in the generated HTML and did so by calling BeginForm

ASP。NET MVC 3具有动态内容的不引人注目的客户端验证——他需要在生成的HTML中显示不引人注目的验证属性,并通过调用BeginForm来实现

ASP.Net MVC 3 validation on AjaxForm - The asker was using Ajax.BeginForm which uses MicrosoftAjax instead of JQuery.validation.

ASP。AjaxForm上的Net MVC 3验证——请求者使用的是Ajax。BeginForm使用MicrosoftAjax而不是JQuery.validation。

PartialView and unobtrusive client validation not working - He had the problem with unobtrusive validation attributes not showing up and overrode ViewContext.FormContext as a workaround.

部分视图和不引人注目的客户端验证无效——他遇到了不引人注目的验证属性不显示和覆盖ViewContext的问题。FormContext作为解决方案。

ASP.NET MVC 3: Generate unobtrusive validation when BeginForm is on the layout - Workaround for unobtrusive validation attributes not showing up in HTML

ASP。NET MVC 3:当BeginForm在布局上时生成不引人注目的验证——解决在HTML中没有出现的不引人注目的验证属性

Relevant Links

Brad Wilson's Unobtrusive Client Validation in ASP.NET MVC 3

Brad Wilson在ASP中不引人注目的客户验证。净MVC 3

The Complete Guide To Validation In ASP.NET MVC 3 - Part 1

在ASP中完整的验证指南。NET MVC 3 -第1部分

The Complete Guide To Validation In ASP.NET MVC 3 - Part 2

在ASP中完整的验证指南。NET MVC 3 -第2部分

Unobtrusive Client-side Validation with Dynamic Contents in ASP.NET MVC 3

使用ASP动态内容的不引人注目的客户端验证。净MVC 3

1 个解决方案

#1


55  

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

在这一点上,我认为以下是一套完整的要求:

  1. Create a form with Html.BeginForm
  2. 使用Html.BeginForm创建一个表单
  3. Turn on ClientValidationEnabled
  4. 打开ClientValidationEnabled
  5. Turn on UnobtrusiveJavaScriptEnabled
  6. 打开UnobtrusiveJavaScriptEnabled
  7. Set appropriate validation attributes on the model's properties (not fields)
  8. 在模型的属性(而不是字段)上设置适当的验证属性
  9. 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)
  10. 如果用于创建表单元素的Html helper与Html不在同一表单中。BeginForm调用,使用相关的工作区(参见工作区1和工作区2)
  11. Include jquery, jquery.validate.js, and jquery.validate.unobtrusive.js files, in that order
  12. 包括jquery,jquery.validate。js和jquery.validate.unobtrusive。js文件,按照这个顺序。
  13. Verify that the unobtrusive validation attributes are present in the HTML
  14. 验证不显眼的验证属性是否存在于HTML中
  15. If using custom validators:
    • ensure that they are added to jQuery.validator.unobtrusive.adapters
    • 确保将它们添加到jquery .validator.unobtrusive.adapter
    • ensure that they are added to the jQuery validation plugin by calling jQuery.validator.addMethod.
    • 通过调用jQuery.validator. addmethod,确保将它们添加到jQuery验证插件中。
    • ensure that the above happen before $(document).ready() as at that point it's too late
    • 确保在$(document).ready()之前发生上述情况,此时已经太晚了。
  16. 如果使用自定义验证器:请确保将它们添加到jQuery.validator.unobtrusive。适配器通过调用jQuery.validator. addmethod确保将它们添加到jQuery验证插件中。确保在$(document).ready()之前发生上述情况,此时已经太晚了。
  17. Call jQuery.validator.unobtrusive.parse or jQuery.validator.unobtrusive.parseElement on elements added dynamically after the initial page load.
  18. jQuery.validator.unobtrusive打电话。解析或jQuery.validator.unobtrusive。在初始页面加载之后动态添加元素的parseElement。

#1


55  

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

在这一点上,我认为以下是一套完整的要求:

  1. Create a form with Html.BeginForm
  2. 使用Html.BeginForm创建一个表单
  3. Turn on ClientValidationEnabled
  4. 打开ClientValidationEnabled
  5. Turn on UnobtrusiveJavaScriptEnabled
  6. 打开UnobtrusiveJavaScriptEnabled
  7. Set appropriate validation attributes on the model's properties (not fields)
  8. 在模型的属性(而不是字段)上设置适当的验证属性
  9. 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)
  10. 如果用于创建表单元素的Html helper与Html不在同一表单中。BeginForm调用,使用相关的工作区(参见工作区1和工作区2)
  11. Include jquery, jquery.validate.js, and jquery.validate.unobtrusive.js files, in that order
  12. 包括jquery,jquery.validate。js和jquery.validate.unobtrusive。js文件,按照这个顺序。
  13. Verify that the unobtrusive validation attributes are present in the HTML
  14. 验证不显眼的验证属性是否存在于HTML中
  15. If using custom validators:
    • ensure that they are added to jQuery.validator.unobtrusive.adapters
    • 确保将它们添加到jquery .validator.unobtrusive.adapter
    • ensure that they are added to the jQuery validation plugin by calling jQuery.validator.addMethod.
    • 通过调用jQuery.validator. addmethod,确保将它们添加到jQuery验证插件中。
    • ensure that the above happen before $(document).ready() as at that point it's too late
    • 确保在$(document).ready()之前发生上述情况,此时已经太晚了。
  16. 如果使用自定义验证器:请确保将它们添加到jQuery.validator.unobtrusive。适配器通过调用jQuery.validator. addmethod确保将它们添加到jQuery验证插件中。确保在$(document).ready()之前发生上述情况,此时已经太晚了。
  17. Call jQuery.validator.unobtrusive.parse or jQuery.validator.unobtrusive.parseElement on elements added dynamically after the initial page load.
  18. jQuery.validator.unobtrusive打电话。解析或jQuery.validator.unobtrusive。在初始页面加载之后动态添加元素的parseElement。