Currently, I am using <%= String.Format(“{0:MMM dd, yyyy}”, DateTime.Now)%> to get today’s date in Jul 27, 2011 format.
Now, I want to get today’s date from model instead of using String.Format in my view (whic is not a good way).
Anyone can help me how to do this in Model.
I am using Asp.net MVC2.
I tried in my property something like:
[DisplayName("Display Date")]
[DisplayFormat(DataFormatString = "{0:MMM dd, yyyy}")]
public DateTime DisplayDate { get; set; }
And in view i tried:
<%= Html.DisplayFor(model => model.DisplayDate) %>
Weird, the following works great for me.
Model:
Controller:
View:
Output HTML: