Jus*_*son 26 c# asp.net-core-mvc asp.net-core asp.net-core-1.0
在以前的ASP.NET MVC版本中,向模型添加自定义验证的方法是实现IValidatableObject并实现自己的Validate()方法.举个例子:
public class BestModelEver : IValidatableObject {
public DateTime? Birthday { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
if (Birthday.HasValue) {
yield return new ValidationResult("Error message goes here");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这仍然是向ASP.NET Core中的模型添加自定义验证的推荐方法吗?使用依赖IValidatableObject于System.ComponentModel.DataAnnotations依赖.
| 归档时间: |
|
| 查看次数: |
16564 次 |
| 最近记录: |