我正在使用这样的 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; } }
那么如何从自定义验证属性中获取错误消息呢?