如何仅使月份和年份出现ASP.NET MVC [英] How to only make month and year appear ASP.NET MVC
本文介绍了如何仅使月份和年份出现ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试显示月份和年份,而不是dd/mm/yyyy.我的代码如下:
I am trying to get the month and year to appear instead of dd/mm/yyyy. My code is below:
在此处输入模型代码
[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?
Is there a way where I can only make mm/yyyy appear?
推荐答案
应用此属性.我已经对此进行了测试,并且工作正常.
Apply this attribute. I have tested this and works fine.
[DisplayFormat(DataFormatString ="{0:MM/yyyy}",ApplyFormatInEditMode =true)]
这篇关于如何仅使月份和年份出现ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文