在TextBoxFor()中显示格式化的日期 [英] Display a formatted date in a TextBoxFor()
问题描述
我正在使用MVC4和Entity Framework开发Intranet Web应用程序.我有一个可以编辑的人员清单.当我访问编辑视图时,在文本框开始日期"中,日期显示如下:7/11/2013 00:00:00
.我想做的是以yyyy/MM/dd格式显示.我尝试了String.Format("{0:yyyy/MM/dd}", item.StartDate)
,但是它不起作用.我也尝试使用注释[DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]
,但它也不起作用.
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.
在我看来,我有这个:
<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" })
这篇关于在TextBoxFor()中显示格式化的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!