I'm using ASP.NET MVC and implementing custom validation via custom attributes/data annotations on my models.
Is it possible to access a property on an object's parent class inside my custom attribute?
public class MyModel
{
[MyCustomValidator]
public string var1 {get; set;}
public string var2 {get; set;}
}
Note: Using asp.net mvc
public class MyCustomValidatorAttribute : ValidationAttribute
{
public bool override IsValid(Object value)
{
// somehow get access to var2 in the MyModel
}
}
So basically, making validation check another property for a specific value. I tried to pass var2
's value as a parameter to MyCustomValidator
but that doesn't work.