【发布时间】:2015-11-17 01:23:26
【问题描述】:
我在 Visual Studio 2013 中使用 asp.net mvc,其中一个字段是日期输入,但是当单击该字段并将焦点放在该字段中时,自动 HTML5 日期选择器不会出现。如果我手动输入该字段,它会出现,但它不会映射到该特定字段。在数据注释中,我包含了 [DataType(DataType.Date)] 但这并没有显示 HTML5 日期选择器。我如何在 asp.net 中实现这一点,特别是该字段的代码
<div class="form-group">
@Html.LabelFor(model => model.CustomerJoinDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CustomerJoinDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CustomerJoinDate, "", new { @class = "text-danger" })
</div>
</div>
【问题讨论】:
-
将属性 type="date" 添加到 htmlattributes 括号中怎么样?
-
感谢大家的建议,我所做的是将 type="date" 放在“EditorFor”行的 html 属性中,这样就成功了
-
如果您想使用 editorfor 而不是 textboxfor,我会在我的答案中添加示例
标签: asp.net-mvc html datepicker