私のモデル
[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 形式の日付を許可していません。私は何日もの間問題を理解してきました。