I am using DataAnnotations tags for client-side validation in ASP.NET MVC2. I am using the Required tag, but in my case marking a field as required is not always an absolute. I have other conditions that determine whether or not a field is required.
Is it possible to override the required tag to allow for this conditional logic?
I would like to do something like this:
public class ConditionalRequiredAttribute : RequiredAttribute
{
public ConditionalRequiredAttribute(string someParameter)
{
//Logic to determine if this field is required.
}
}
And then use this attribute like this:
[ConditionalRequired("some parameter info")]
public virtual string EMailAddress { get; set; }
Any suggestions on how to make this work for client-side validation?
Thanks!