【发布时间】:2012-09-23 13:20:56
【问题描述】:
我正在使用这样的 CustomValidationAttribute
[CustomValidation(typeof(MyValidator),"Validate",ErrorMessage = "Foo")]
我的验证器包含此代码
public class MyValidator { public static ValidationResult Validate(TestProperty testProperty, ValidationContext validationContext) { if (string.IsNullOrEmpty(testProperty.Name)) { return new ValidationResult(""); <-- how can I get the error message from the custom validation attribute? } return ValidationResult.Success; } }
那么如何从自定义验证属性中获取错误消息?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3 data-annotations customvalidator