ASP.NET MVC 3:动态/ AJAX内容不显眼的客户端验证所需的步骤 [英] ASP.NET MVC 3: Required steps for unobtrusive client-side validation of dynamic/AJAX content
问题描述
什么是全套的步骤所需作为客户端不引人注目的验证,为动态插入表单字段工作?
What are the complete set of Steps Required for client-side unobtrusive validation to work for dynamically inserted form fields?
<一个href=\"http://stackoverflow.com/questions/6124992/asp-net-mvc-3-unobtrusive-client-side-validation-with-dynamic-content\">ASP.NET MVC 3动态内容不显眼的客户端验证 - 他需要在不显眼的属性验证,在生成的HTML展现出来,并通过调用这样做 BeginForm
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上当作ajaxForm 3验证 - 提问者使用 Ajax.BeginForm
它使用MicrosoftAjax而不是JQuery.validation。
ASP.Net MVC 3 validation on AjaxForm - The asker was using Ajax.BeginForm
which uses MicrosoftAjax instead of JQuery.validation.
<一个href=\"http://stackoverflow.com/questions/4187742/partialview-and-unobtrusive-client-validation-not-working\">PartialView和不显眼客户端验证工作不 - 他与不显眼的验证问题的属性没有显示出来,并压倒了 ViewContext.FormContext
作为一种解决方法
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.
<一个href=\"http://stackoverflow.com/questions/4997269/asp-net-mvc-3-generate-unobtrusive-validation-when-beginform-is-on-the-layout\">ASP.NET MVC 3:生成不显眼的审定时BeginForm是在布局 - 解决方法不显眼的验证属性不显示HTML高达
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
Brad Wilson's Unobtrusive Client Validation in ASP.NET MVC 3
<一个href=\"http://weblogs.asp.net/imranbaloch/archive/2011/03/05/unobtrusive-client-side-validation-with-dynamic-contents-in-asp-net-mvc.aspx\">Unobtrusive客户端验证与ASP.NET MVC 3 动态内容
推荐答案
在这一点上,我相信下面的是一套完整的要求:
At this point I believe the following is a complete set of requirements:
- 创建与
Html.BeginForm
表格 - 打开
ClientValidationEnabled
- 打开
UnobtrusiveJavaScriptEnabled
- 设置适当的验证对模型的属性的属性(的不的字段)
- 如果正在使用的HTML辅助创建表单元素是不一样的形式
Html.BeginForm
呼叫,使用相应的解决方法(见<一href=\"http://stackoverflow.com/questions/4187742/partialview-and-unobtrusive-client-validation-not-working\">workaround 1 和<一个href=\"http://stackoverflow.com/questions/4997269/asp-net-mvc-3-generate-unobtrusive-validation-when-beginform-is-on-the-layout\">workaround 2 ) - 包含
的jQuery
,jquery.validate.js
和jquery.validate.unobtrusive .js文件
文件,顺序 - 验证不显眼的验证属性在HTML present
- 如果使用自定义验证:
- 确保它们添加到
jQuery.validator.unobtrusive.adapters
- 确保它们通过调用添加到jQuery的验证插件
jQuery.validator.addMethod
。 - 确保上述前发生
$(文件)。就绪()
作为在这一点为时已晚
- 确保它们添加到
- Create a form with
Html.BeginForm
- Turn on
ClientValidationEnabled
- Turn on
UnobtrusiveJavaScriptEnabled
- Set appropriate validation attributes on the model's properties (not fields)
- 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) - Include
jquery
,jquery.validate.js
, andjquery.validate.unobtrusive.js
files, in that order - Verify that the unobtrusive validation attributes are present in the HTML
- 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
- ensure that they are added to
这篇关于ASP.NET MVC 3:动态/ AJAX内容不显眼的客户端验证所需的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!