我的模特
[UIHint("Date")]
[DisplayFormat(NullDisplayText="", DataFormatString = " {0:dd/MM/yyyy}")]
public DateTime Date { get; set; } // Date
显示模板日期
@model DateTime?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new
{
@class = "datepicker"
})
View
<div class="control-group">
@Html.LabelFor(model => model.Date, new { @class = "control-label" })
<div class="controls">
@Html.EditorFor(model => model.Date)
@Html.ValidationMessageFor(model => model.Date, null, new { @class = "help-inline" })
</div>
</div>
Javascript
$.fn.datepicker.defaults.format = "dd/mm/yyyy";
$('.datepicker').datepicker({
autoclose: true,
format: "dd/mm/yyyy"
});
Datepicker 仍然不允许 dd/mm/yyyy 格式日期。几天以来,我一直在找出问题所在。