asp.net-mvc - 每个验证属性的所有不显眼的验证属性的列表

标签 asp.net-mvc validation unobtrusive-validation unobtrusive-javascript

我需要每个验证属性的所有不显眼的验证属性的引用列表。像这样的东西:

enter image description here

最佳答案

MVC 为其提供的每个数据注释验证器附带了不显眼的验证器。取自Validation with Data Annotation Validators ,这是该列表:

Using the Data Annotation Validator Attributes

When you use the Data Annotations Model Binder, you use validator attributes to perform validation. The System.ComponentModel.DataAnnotations namespace includes the following validator attributes:

  • Range – Enables you to validate whether the value of a property falls between a specified range of values.
  • ReqularExpression – Enables you to validate whether the value of a property matches a specified regular expression pattern.
  • Required – Enables you to mark a property as required.
  • StringLength – Enables you to specify a maximum length for a string property.
  • Validation – The base class for all validator attributes.
  • DataType - Additional validations for specific data types, like phone numbers, credit cards and email addresses. Not in the referenced link.

另请参阅https://dataannotationsextensions.apphb.com了解可以包含在您的应用程序中的其他验证器。

就客户端标签属性而言,这些属性由上述注释生成的不显眼的适配器进行处理。它们以“data-val-”为前缀。验证器的附加参数将作为附加属性添加。例如: 正则表达式变为 data-val-regex=“Message” data-val-regex-pattern=“某种模式”

来自 MVC3 jQuery.validate.unobtrusive.js:

adapters.addSingleVal("accept", "exts")
        .addSingleVal("regex", "pattern");

adapters.addBool("creditcard")
        .addBool("date")
        .addBool("digits")
        .addBool("email")
        .addBool("number")
        .addBool("url");

adapters.addMinMax("length", "minlength", "maxlength", "rangelength")
        .addMinMax("range", "min", "max", "range");

adapters.add("equalto", ["other"], function (options) {
        // removed for brevity
});
adapters.add("required", function (options) {
    // removed for brevity
});
adapters.add("remote", ["url", "type", "additionalfields"], function (options) {
    // removed for brevity
});

关于asp.net-mvc - 每个验证属性的所有不显眼的验证属性的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32356661/

相关文章:

asp.net-mvc - 403 - 禁止 : Access is denied. ASP.Net MVC

c# - 在 ASP.NET MVC 3 中为 Controller 设置默认操作(而不是索引)

javascript - 我如何使用正则表达式验证 javascript 中的 url

jquery-plugins - 当不同目标的不同事件被触发时显示单个qtip?

asp.net-mvc-3 - 在 ASP.NET MVC 3 中使用不显眼的验证,当表单无效时如何采取行动?

javascript - 我应该在 asp mvc 中使用不显眼的 javascript 而不是编写自己的验证代码吗?

asp.net-mvc - Visual Studio 2013 无法打开 Razor View - 'The operation could not be completed'

asp.net-mvc - 将项目从 ASP.NET MVC1 迁移到 ASP.NET MVC2

ruby-on-rails - 验证消息助手或检索验证错误

jquery - ASP.Net MVC 3 不显眼的客户端验证不适用于下拉列表