【发布时间】:2011-11-12 20:15:24
【问题描述】:
我刚刚注意到DataTypeAttribute 类继承自System.ComponentModel.DataAnnotations.ValidationAttribute。
就 ASP.NET MVC DefaultModelBinder 类而言,DataTypeAttribute 是验证属性吗?通俗点说,ModelBinder 是否根据DataTypeAttribute 验证对象?
例如,如果我将DataType 属性指定为DataType.EmailAddress,它将验证电子邮件地址还是该属性仅提供对象的元数据。
更新
我在 SO 上发现了一个类似的问题:
Is the DataTypeAttribute validation working in MVC2?
因此,据此它不能用作验证属性。那么,如果它不作为验证属性,为什么它是从System.ComponentModel.DataAnnotations.ValidationAttribute 继承的呢?
【问题讨论】:
标签: asp.net .net asp.net-mvc data-annotations asp.net-mvc-validation