我重写了RequiredAttribute,在我的IsValid方法中,我需要能够更改ErrorMessage属性.这可能吗?
[Required(ErrorMessage = "Some custom required message about the Foo property")]
public string Foo { get; set; }
Run Code Online (Sandbox Code Playgroud)
并在IsValid方法内:
public class MyRequiredAttribute : RequiredAttribute
{
public override bool IsValid(object value)
{
ErrorMessage = "Some custom required message";
...
return base.IsValid(value);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3621 次 |
| 最近记录: |