Your requirements are pretty picky...
Specifying the attribute Datatype
for a field, will generate an input
having as type
the attribute specified. That's why when you add [DataType(DataType.Date)]
, the input generated will be a date picker, but if you add [DataType(DataType.DateTime)]
, the input will be of type datetime
, thus why you don't get any picker displayed. Why? Because a few years ago, the browsers supporting input datetime
decided to stop supporting it and W3C removed this feature due to lack of implementation.
However, not so long ago, some browser vendors started supporting again datetime-local
which is back on the draft. As of now, the latest versions of Chrome
, Opera
and Microsoft Edge
support it.
One solution would be to use the BootStrap or the jQuery Datetime Picker as Ajay Kumar suggested.
Another one would be, if you don't mind the few supporting browsers, to use datetime-local
. Like this for instance:
@Html.TextBoxFor(model => model.BirthDate, new { type = "datetime-local"})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…