Why is DisplayFormat DataFormatString not working?
Why are you using ApplyFormatInEditMode
if you have set [Editable(false)]
? All ApplyFormatInEditMode
does is format the date if you have it in a text box or something for editing, which you probably won't because of the aforementioned.
I was able to get the date to display correctly using the following:
[DisplayFormat(DataFormatString = "{0:yyyy/MM/dd}")]
public DateTime Date
{
get
{
return DateTime.Now;
}
set
{
Date = DateTime.Now;
}
}
and in the view (with resulting output):
@Html.DisplayFor(x => x.Date) // 2013/05/23
<br />
@Model.Date // 23/05/2013 09:57:56
<br />
@Html.DisplayFor(x => Model.Date) // 2013/05/23
Hope this helps.
Since You want to exclude the time to get Only Date: At Model:-
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy/MM/dd}"]
public DateTime TheDate { get; set; }
At Views:-
@Html.DisplayFor(model=> model.TheDate)
@Html.JQueryUI().DatepickerFor(model => model.TheDate)
The tutorial of the following link may help you.It works for me.
http://ilyasmamunbd.blogspot.com/2014/02/jquery-ui-datepicker-popup-calendar.html
If you can't get it working on the model, you could try it on the view.
@Html.TextBoxFor(m => m.ValidFrom, "{0:dd/MM/yyyy}", new {maxlength = 10})