在我的模型中
[DataType(DataType.Date)]
[Display(Name="Event Date")]
[DisplayFormat(DataFormatString = "{0:d}")]
//[DisplayFormat(ApplyFormatInEditMode=true ,DataFormatString="{0:DD/MM/YYYY}")]
public DateTime EventDate { get; set; }
在我的视图中(Create.cshtml)
<div class="editor-label">
@Html.LabelFor(model => model.EventDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.EventDate)
@Html.ValidationMessageFor(model => model.EventDate)
</div>
在 Shared/EditorTemplates/Date.cshtml
@model DateTime
@Html.TextBox("", String.Format("{0:d}", Model.ToShortDateString()),
new { @class = "datefield", type = "date" })
并出现以下错误
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.