I'm just dealing with custom validation attributes, and I'm trying to write a custom validation attribute that will be placed at the class level to check for several properties of my model.
I can access all the properties of my model, and I want to be able to check several conditions in my IsValid overload and report it, having different error messages as follows (simplified example).
public override bool IsValid(object value) { var model = (MyObject) value;
But when I do this, I get an exception the first time that ErrorMessage refers to "Cannot set property more than once.
Now I could split my user attribute into several user attributes, but I hoped there would be one way to do this in one, otherwise I would repeat βcatch allβ in each
//if this value is set, I don't want to do anything other checks if (model.Prop3) { return true; }
I already had a search, but I could not find anything, so I apologize if I miss anything obvious.
early!
source share