Date field does not display the value in Chrome browser

让人想犯罪 __ 提交于 2019-12-22 07:05:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!