I am using visual studiio 2015 and i am using its default datetime picker in my MVC5\'s App. i am facing problem while showing the datetime picker. it is showing only date picke
There is no default datetime picker in MVC5. What the [DataType]
attribute does is render the type
attribute for the <input>
element your generating that will then be used by the browser to render the appropriate HTML5 control if supported. In the case of DataType.Date
, it generates <input type="date" ... />
At the current time only recent versions of Chrome support type="date"
. If you tested this using IE or FireFox, you would only get a standard textbox.
Using [DataType(DataType.DateTime)]
generates type="datetime"
but this is not currently supported in either Chrome, IE or FireFox, which is why you see only the standard textbox.
Recent versions of Chrome however do support type="datetime-local"
which will render a control allowing you to select both a date and a time. There is no [DataType]
type which generates this but you can use
@Html.TextBoxFor(m => m.start_date_time, "{0:s}", new { @type = "datetime-local" })
Note "{0:s"}
is shorthand for "{0:yyyy-MM-ddTHH:mm:ss}"
You can compare various versions of browsers and which of the HTML5 field types they support using this site.
Due to the current limited support, I recommend you consider using a jquery datetimepicker plugin rather than browsers HTML implementations.