I am overriding the RequiredAttribute and in my IsValid method I need the ability to change the ErrorMessage property. Is this possible?
[Required(ErrorMessage = "Some custom required message about the Foo property")]
public string Foo { get; set; }
and inside the IsValid method:
public class MyRequiredAttribute : RequiredAttribute
{
public override bool IsValid(object value)
{
ErrorMessage = "Some custom required message";
...
return base.IsValid(value);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With