在我的视图模型中有这个属性:
[DataType(DataType.DateTime)]
public DateTime? StartDate { get; set; }
如果我想显示日期,或者用日期填充一个文本框,我可以这样做:
<%: Model.StartDate %>
<%: Html.TextBoxFor(m => m.StartDate) %>
无论何时显示日期,它都像这样显示: 01/01/201112:00:00 AM
But I'd like to only display 2011年1月1日
Is there a way to apply a display format with data annotations? I don't want to have to go to every instance where I display a date, and add some code to format it.