6

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

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
user2617025
  • 81
  • 1
  • 3

1 Answers1

19

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" />
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575