加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 06:39:30 所属栏目:asp.Net 来源:网络整理
导读:我需要每个验证属性的所有不显眼的验证属性的参考列表.就像是: 解决方法 MVC为它提供的每个数据注释验证器提供了不显眼的验证器.从 Validation with Data Annotation Validators开始,这是列表: Using the Data Annotation Validator Attributes When you u
我需要每个验证属性的所有不显眼的验证属性的参考列表.就像是:

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.
  • DataTypeAdditional 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 =“some 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
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读