Asp.net mvc MVC在索引视图中更改日期格式
我有一个indexView,其中有一个名为Month的列,带有“day-m-y time”,我只想显示月份和年份名称。 我怎么做?我试过数据注释,但不起作用。。Asp.net mvc MVC在索引视图中更改日期格式,asp.net-mvc,jquery-ui-datepicker,Asp.net Mvc,Jquery Ui Datepicker,我有一个indexView,其中有一个名为Month的列,带有“day-m-y time”,我只想显示月份和年份名称。 我怎么做?我试过数据注释,但不起作用。。 [必需] [数据类型(DataType.Date)] [DisplayFormat(DataFormatString=“{0:MM/dd/yyyy}”)] [显示(Name=“选择月份”)] 公共可空月份{get;set;} 该视图包含以下内容: <th data-field="@Html.DisplayNameFor(mo
[必需]
[数据类型(DataType.Date)]
[DisplayFormat(DataFormatString=“{0:MM/dd/yyyy}”)]
[显示(Name=“选择月份”)]
公共可空月份{get;set;}
该视图包含以下内容:
<th data-field="@Html.DisplayNameFor(model => model.Month)">
@Html.DisplayNameFor(model => model.Month)
</th>
@Html.DisplayNameFor(model=>model.Month)
您可以在视图示例中设置日期格式,如下所示
<span>@Convert.ToDateTime(item.EffectiveDate).ToString("MMM-yyyy")</span>
@Html.DisplayNameFor
将打印属性的名称,即月份
,而不是其值。如何呈现这些值?
<span>@Convert.ToDateTime(item.EffectiveDate).ToString("MMM-yyyy")</span>
[Display(Name = "For Period")]
[DisplayFormat(DataFormatString = "{0:MMM-yyyy}")]