尝试了与DataFormatString
相关的各种解决方案但是没有什么对我来说跟随一段代码(日期格式dd-MM-yyyy
没有在html表单中应用)
[Column("dateOfBirth")]
[Required]
[DataType(DataType.Date), DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MM-yyyy}")]
[Display(Name = "Date Of Birth")]
public virtual DateTime DateOfBirth { get; set; }
和html内部
<div class="form-group">
@Html.LabelFor(model => model.DateOfBirth, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DateOfBirth, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DateOfBirth, "", new { @class = "text-danger" })
</div>
</div>