我有一个构建在Bootstrap 3和ASP.NET MVC 5上的视图,用于编辑用户配置文件信息,但它在表单上显示的格式不正确。
数据库是Neo4j,我使用Neo4jClient从.NET与数据库交互。Neo4j客户端需要使用
DateTimeOffset
对象,而不是
DateTime
对象,以使用Json.NET的序列化程序传递给Neo4j的REST接口。因此,我的模型使用DateTimeOffset对象来存储用户的生日。
以下是我视图中的表单字段:
<div class="form-group">
<label class="col-md-4 control-label" for="Birthday">Birthday</label>
<div class="col-md-4">
@Html.TextBoxFor(model => model.Birthday, new { @class = "form-control input-md datepicker", placeholder = "Birthday" })
<span class="help-block">Please enter your birthday</span>
</div>
</div>
打印到表单时,日期的格式如下:
M/dd/yyyy hh:mm:ss t -zzz
然而,它应该具有这种格式,因为我们只需要日期部分:
MM/dd/yyyy
我已经尝试在模型属性上使用DataFormatString注释,但它仍然没有以正确的格式显示:
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTimeOffset Birthday { get; set; }
此批注是否仍然适用于DateTimeOffset对象?如何修复字符串格式?