问题描述
我的剃刀视图定义如下
< input id =date1type =textclass =requiredvalue =@ Model.Date.ToShortDateString()maxlength =10/>
< input id =date2type =dateclass =requiredvalue =@ Model.Date.ToShortDateString()maxlength =10/>
我在Chrome下运行它,第一个输入显示正确的日期值。
第二个输入仅显示mm / dd / yyyy,即使点击向下箭头时的日历显示。
我想要第二个输入字段显示值而不是mm / dd / yyyy
当您在HTML5中使用新的< input type =date...
时,您需要传递ISO中的值格式,它是 yyyy-MM-dd
。因此,将您的标记更改为:
< input id =date2type =dateclass =requiredvalue = @ Model.Date.ToString(yyyy-MM-dd)maxlength =10/>
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
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" />
这篇关于日期字段不会在Chrome浏览器中显示该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!