我为出生日期创建了验证属性,如下所示:
public class DateRequired : ValidationAttribute
{
public override bool IsValid(object value)
{
DateTime date = Convert.ToDateTime(value);
return date != DateTime.MinValue;
}
}
public class DateGraterThanEighteen : ValidationAttribute
{
public override bool IsValid(object value)
{
DateTime date = Convert.ToDateTime(value);
long ticks = DateTime.Now.Ticks - date.Ticks;
int years = new DateTime(ticks).Year;
return years >= 18;
}
}
I applied attributes like this
[DateGraterThanEighteen(ErrorMessage="You must be at least 18")]
[DateRequired(ErrorMessage = "Date of birth is required")]
public DateTime DateOfBirth { get; set; }
无论我应用它们的顺序如何,DateGraterThanEighteen 都会首先执行。我怎样才能让 DateRequired 先执行?