我試圖讓月和年出現,而不是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