i have a model like this :
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy/MM/dd HH:mm:ss}", ApplyFormatInEditMode = true)]
public DateTime DateUpdate { get; set; }
并且有一个视图:
<div class="form-group">
@Html.LabelFor(model => model.DateUpdate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Helpers.EditVal(Html.EditorFor(m => m.DateUpdate, new { htmlAttributes = new { @class = "form-control", @Value = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss") } }))
@Html.ValidationMessageFor(model => model.DateUpdate, "", new { @class = "text-danger" })
</div>
</div>
但我无法保存它,因为在dateupdate字段上出现了验证错误!这里有什么问题?我想以这种格式保存{0:yyyy/MM/dd HH:mm:ss}
,而不是mm/dd/yy或其他一些格式,并且我不想出现验证错误。