在EditorFor()中显示格式化的日期 [英] Display a formatted date in an EditorFor()
本文介绍了在EditorFor()中显示格式化的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
7/11/2013 00:00:00
。我想要做的是以yyyy / MM / dd的格式显示它。我尝试了 String.Format({0:yyyy / MM / dd},item.StartDate)
,但它不起作用。我还尝试使用注释 [DisplayFormat(DataFormatString ={0:dd MMM yyyy})]
,但它不起作用。 在我看来,我有这样的:
< div class =editor-field>
@ Html.TextBoxFor(model => model.StartDate,new {@class =datepicker})
@ Html.ValidationMessageFor(model => model.StartDate)
< / div>
任何想法如何做?
解决方案
@Html.TextBoxFor(m => m.StartDate,
new {@Value = Model.StartDate.ToString(yyyy / MM / dd),@ class =datepicker})
I'm using MVC4 and Entity Framework to develop an intranet web app. I have a list of persons which I can edit. When I access the edit view, in the textbox "Start date", the date is displayed like this : 7/11/2013 00:00:00
. What I want to do is to display it in the format yyyy/MM/dd. I tried the String.Format("{0:yyyy/MM/dd}", item.StartDate)
but it does not work. I also tried with the annotation [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]
but it does not work neither.
In my view I have this :
<div class="editor-field">
@Html.TextBoxFor(model => model.StartDate, new { @class = "datepicker" })
@Html.ValidationMessageFor(model => model.StartDate)
</div>
Any idea about how to do?
解决方案
@Html.TextBoxFor(m => m.StartDate,
new { @Value = Model.StartDate.ToString("yyyy/MM/dd"), @class="datepicker" })
这篇关于在EditorFor()中显示格式化的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文