问题
I am having problem binding date value in Chrome browser.
My razor view defined as follow
<input id="date1" type="text" class="required" value="@Model.Date.ToShortDateString()" maxlength="10" />
<input id="date2" type="date" class="required" value="@Model.Date.ToShortDateString()" maxlength="10" />
I ran it under Chrome, the first input display the date value correct. the second input only display mm/dd/yyyy even though a calendar display when I click on the down arrow.
I would like to have the second input field to show the value instead of mm/dd/yyyy
回答1:
When you use the new <input type="date" ...
in HTML5, you need to pass the value in ISO format, which is yyyy-MM-dd
. So change your markup to:
<input id="date2" type="date" class="required" value="@Model.Date.ToString("yyyy-MM-dd")" maxlength="10" />
来源:https://stackoverflow.com/questions/18157045/date-field-does-not-display-the-value-in-chrome-browser