Data Annotation Ranges of Dates
问题 Is it possible to use [Range] annotation for dates? something like [Range(typeof(DateTime), DateTime.MinValue.ToString(), DateTime.Today.ToString())] 回答1: Docs on MSDN says you can use the RangeAttribute [Range(typeof(DateTime), "1/2/2004", "3/4/2004", ErrorMessage = "Value for {0} must be between {1} and {2}")] public datetime Something { get; set;} 回答2: I did this to fix your problem public class DateAttribute : RangeAttribute { public DateAttribute() : base(typeof(DateTime), DateTime.Now