【发布时间】:2013-11-10 23:04:01
【问题描述】:
如果我在 MVC 中使用 EditFor,我的 DateTime 字段会显示未格式化的日期时间,如果我使用旧式 html,我的字段不会收到错误类。
<div class="editor-field">
<input type="text" name="EstimateTime" id="EstimateTime" value="<%: (Model != null) ? Model.EstimateTime.ToString("dd/MM/yyyy hh:mm:ss tt") : "" %>" />
<%: Html.TextBoxFor(model => model.EstimateTime, new { @value = (Model != null) ? Model.EstimateTime.ToString("dd/MM/yyyy hh:mm:ss tt") : "" })%>
<%: Html.ValidationMessageFor(model => model.EstimateTime) %>
</div>
result HTML:看值的区别:
<div class="editor-field">
<input type="text" name="EstimateTime" id="EstimateTime" value="31/10/2013 01:54:42 PM" class="hasDatepicker">
<input id="EstimateTime" name="EstimateTime" type="text" value="10/31/2013 1:54:42 PM" class="input-validation-error text-box single-line">
<span class="field-validation-error">Isn't a date/time valid</span>
</div>
修复它的最佳做法是什么?
【问题讨论】:
-
它把日期换成了月份。有什么大不了的?
-
问题是,如果我使用 Model.EstimateTime.ToString("dd/MM/yyyy hh:mm:ss tt") 日期显示格式为 MM/dd/.....
标签: asp.net-mvc