Data Annotation Ranges of Dates

后端 未结 7 1340
故里飘歌
故里飘歌 2020-12-08 18:53

Is it possible to use [Range] annotation for dates?

something like

[Range(typeof(DateTime), DateTime.MinValue.ToString(), DateTime.To         


        
7条回答
  •  囚心锁ツ
    2020-12-08 19:18

    I did this to fix your problem

     public class DateAttribute : RangeAttribute
       {
          public DateAttribute()
            : base(typeof(DateTime), DateTime.Now.AddYears(-20).ToShortDateString(),     DateTime.Now.AddYears(2).ToShortDateString()) { } 
       }
    

提交回复
热议问题