Custom ValidationAttribute test against whole model

Posted by griegs on Stack Overflow See other posts from Stack Overflow or by griegs
Published on 2010-04-15T23:05:09Z Indexed on 2010/04/15 23:13 UTC
Read the original article Hit count: 521

I know this is probably not possible but let's say I have a model with two properties.

I write a ValidationAttribute for one of the properties. Can that VA look at the other property and make a decision?

So;

public class QuickQuote
{
    public String state { get; set; }

    [MyRequiredValidator(ErrorMessage = "Error msg")]
    public String familyType { get; set; }

So in the above example, can the validator test to see what's in the "state" property and take that into consideration when validating "familyType"?

I know I can probably save the object to the session but would like to avoid any saving of state if possible.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about dataannotations