RequiredIfTrue - Multiple Targets

Aug 23, 2011 at 2:58 PM

I have a view model consisting of 4 boolean properties and one string property.  The string field is required if any of the boolean fields are true.  I have not found a way to easily use foolproof to accomplish this requirement.  Am I missing something?  Is there a built-in way to do this?

I receive an error when attempting to decorate the property with multiple RequiredIfTrue attributes.

Thanks.

Coordinator
Aug 23, 2011 at 3:11 PM

It's actually a limitation of .NET that you can't decorate a member with more than one instance of an attribute.

As hacky as it is, I have solved this issue in the past by creating a new attribute class and inheriting from the attribute I actually want to use. 

Nov 6, 2013 at 1:42 PM
Multiple attribute is possible in .net with AllowMultiple

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RequiredCustomIfAttribute : ValidationAttribute, IClientValidatable