我试图让月和年出现,而不是dd/mm/yyyy。 我的代码如下:如何才能使月份和年份显示ASP.NET MVC
继承人的型号代码
[Display (Name = "ValidFrom")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MMM-yyyy}" , ApplyFormatInEditMode = true)]
public System.DateTime ValidFrom { get; set; }
这是视图文件
<div class="form-group">
@Html.LabelFor(model => model.ValidFrom, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ValidFrom, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ValidFrom, "", new { @class = "text-danger" })
</div>
</div>
有没有办法,我只能让MM/YYYY出现?
你的datepicker在哪里? – Liam
@Liam我认为他并不是真的指日期选择器,而是指向',请参阅此帖http://stackoverflow.com/questions/7372038/is-there-any-way-要改变输入类型的日期格式 – SOfanatic
@Liam对此表示抱歉。 – John