用于日期的ASP.NET MVC 5 DataFormatString不起作用

时间:2017-08-16 13:25:55

标签: asp.net asp.net-mvc visual-studio-2015

尝试了与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>

0 个答案:

没有答案