Data Annotation Ranges of Dates

后端 未结 7 1402
故里飘歌
故里飘歌 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:13

    For those rare occurrences when you are forced to write a date as a string (when using attributes), I highly recommend using the ISO-8601 notation. That eliminates any confusion as to whether 01/02/2004 is january 2nd or february 1st.

    [Range(typeof(DateTime), "2004-12-01", "2004-12-31",
        ErrorMessage = "Value for {0} must be between {1} and {2}")]
    public datetime Something { get; set;}
    

提交回复
热议问题