【发布时间】:2018-01-07 08:03:01
【问题描述】:
我有以下视图 Edit.cshtml 片段
<div class="form-group">
@Html.LabelFor(model => model.BirthDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.BirthDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BirthDate, "", new { @class = "text-danger" })
</div>
</div>
属性 BirthDate 是 DateTime 的类型。 当我想编辑 BirthDate 时,它只显示格式 rrrr-mm-dd 没有数据,但可以从 datepicker 中选择日期。当我添加
@Html.EditorFor(model => model.BirthDate.Date, new { htmlAttributes = new { @class = "form-control" } })
然后我收到格式为 yyyy-mm-dd HH:MM:SS 的数据,但我无法从 datepicker 中选择日期。
我应该怎么做,以 yyyy-mm-dd 格式获取日期并有可能从 datepicker 中选择日期?
【问题讨论】:
-
尝试在您的 BirthDate 属性中使用数据注释。
标签: asp.net asp.net-mvc razor datepicker