在EditorFor显示格式化的日期() [英] Display a formatted date in an EditorFor()
问题描述
我使用MVC4和Entity Framework开发的Intranet Web应用程序。我有我可以编辑的人员名单。当我访问编辑视图,在文本框开始日期,日期显示是这样的: 2013年7月11日〇点零零分00秒
。我想要做的是格式为yyyy / MM / DD来显示它。我试过的String.Format({0:YYYY / MM / DD},item.StartDate)
,但它不工作。我也试图与注释 [DisplayFormat(DataFormatString ={0:DD MMM YYYY})。
,但它不工作也不
在我看来,我有这样的:
< DIV CLASS =主编场>
@ Html.TextBoxFor(型号=> model.StartDate,新{@class =日期选择器})
@ Html.ValidationMessageFor(型号=> model.StartDate)
< / DIV>
有关如何做任何想法?
@ Html.TextBoxFor(M = GT; m.StartDate,
新{@Value = Model.StartDate.ToString(YYYY / MM / DD),@类=日期选择器})
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屋!