help me with asp.net mvc 2 custom validation attribute
- by Omu
I'm trying to write a validation attribute that is going to check that at least one of the specified properties is true
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class AtLeastOneTrueAttribute : ValidationAttribute
{
private const string DefaultErrorMessage = "select at least one";
public AtLeastOneTrueAttribute(params string[] props)
: base(DefaultErrorMessage)
{
this.props = props;
}
private readonly string[] props;
public override string FormatErrorMessage(string name)
{
return DefaultErrorMessage;
}
public override bool IsValid(object value)
{
var properties = TypeDescriptor.GetProperties(value);
return props.Any(p => (bool) properties.Find(p, true).GetValue(value));
}
}
now when I'm trying to use I can't really get specify the props after the fir , the intellisence shows me that I'm entering the ErrorMessage and only the first string is the params string[] props