I am using data annotation attributes to provide metainfo for client side validation. The following code adds data-val-date
attribute correctly to the corresponding html input element:
[DataType(DataType.Date)]
public DateTime? TestDate { get; set; }
I have date and time input fields too and I would like to apply different validation rules there. However adding different DataType value changes nothing in the rendered input element:
[DataType(DataType.DateTime)]
public DateTime? TestDate { get; set; }
rendered in the very same way I mean it renders also a data-val-date
attribute so at client side the two kinds of input validation is indistinguishable.
As a bonus using
[DataType(DataType.Time)]
public DateTime? TestDate { get; set; }
renders no data-val
attribute.
Then what's the use of the different DataType attributes?. And more importantly, how can I correctly render a data-val-datetime
and data-val-time
attributes? (what I am going to handle in a custom way at client side using jQuery validation)