Reputation: 147
Is there a way to set order of execution of custom validation attributes on property? I have 2 different custom email attributes, One for the email address and another to make sure the email address is in out Active Directory. I want my regular email validation to be first and then the Active Directory validation.
Upvotes: 1
Views: 1782
Reputation: 125277
In General
As described in How can I specify the order of DataAnnotation ValidationAttribute's?
The only way to specify the order is to create your own ModelValidatorProvider which can then order the attributes. This will probably be tricky because you'd also need to create overloads for each attribute that takes an Order parameter ( don't know if they already do ).
But in your case
You can create your custom email attribute to first check validity as email address, then check for existence in active directory. and there is no need to other email validation attribute.
Since the EmailAddressAttribute
is sealed, you can not inherit from that, instead you can use the sourcecode of that class to change and create your own attribute:
Upvotes: 1