我正在使用带数据注释属性的codefirst。该模型如下所示:
public class Incident
{
[Key]
public int IncidentId { get; set; }
[Display(Name = "Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mm}")]
public DateTime Date { get; set; }
}
创建视图:
<div class="editor-label">
@Html.LabelFor(model => model.Date)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Date, "time")
@Html.ValidationMessageFor(model => model.Date)
</div>
当我尝试创建新模型时,在此字段附近会收到验证消息。我什至尝试通过create方法将当前日期传递给视图,但这无济于事。有没有办法只存储hh:mm(没有dd / MM / yyyy)?
如果您真的只对一天中的时间感兴趣,那么可以使用TimeSpan而不是DateTime
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句