DataAnnotations multiple property validation in MVC
Posted
by scottrakes
on Stack Overflow
See other posts from Stack Overflow
or by scottrakes
Published on 2010-05-25T01:09:56Z
Indexed on
2010/05/25
1:21 UTC
Read the original article
Hit count: 568
I am struggling with DataAnnotations in MVC. I would like to validate a specific property, not the entire class but need to pass in another property value to validate against. I can't figure out how to pass the other property's value, ScheduleFlag, to the SignUpType Validation Attribute.
public class Event
{
public bool ScheduleFlag {get;set;}
[SignupType(ScheduleFlag=ScheduleFlag)]
}
public class SignupTypeAttribute : ValidationAttribute
{
public bool ScheduleFlag { get; set; }
public override bool IsValid(object value)
{
var DonationFlag = (bool)value;
if (DonationFlag == false && ScheduleFlag == false)
return false;
return true;
}
}
© Stack Overflow or respective owner