I m trying to add Data Validation To my DateTime Attribut i want to oblige user to select Date between DateTime.Now
and smaller then one years after DateTime.now.addyears(+1)
This is my code :
public class DateDebut : ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null) return false;
DateTime enteredDate = (DateTime)value;
if ( (enteredDate >= DateTime.Now) && (enteredDate <= DateTime.Now.AddYears(+1)))
return true;
else
return false;
}
}
[Required]
[Display(Name = "De : ")]
[DataType(DataType.Date)]
[DateDebut(ErrorMessage="Date invalide")]
public DateTime dd { get; set; }
此自定义验证 dosn t 工作, 验证未执行, 即认为我错过了一些真实的简单吗?