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
Select Settings. In the Date/time formatting settings section of the Settings overlay, use the drop-downs to select your preferences. Use the Dates drop-down to set how dates appear.
Just use <script src="modernizr. js"></script> in the <head> section, and the script will add classes which help you to separate the two cases: if it's supported by the current browser, or if it's not. Save this answer.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With