4
我創建了誕生這樣的日期驗證屬性:數據anntotation屬性。如何設置執行順序?
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先執行?