views:

186

answers:

0

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 bool DonationFlag{get;set;}
 }

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;
        }
    }