What is wrong with the following?
@Convert.ToDateTime((@item.Date.ToShortDateString())," dd - M - yy")
@item.Date is showing 20/11/2005 12:00 a.m and I want to display 20 Nov 2011
What is wrong with the following?
@Convert.ToDateTime((@item.Date.ToShortDateString())," dd - M - yy")
@item.Date is showing 20/11/2005 12:00 a.m and I want to display 20 Nov 2011
For Razor put the file DateTime.cshtml in the Views/Shared/EditorTemplates folder. DateTime.cshtml contains two lines and produces a TextBox with a date formatted 9/11/2001.
In general, the written month is escaped as MMM, the 4-digit year as yyyy, so your format string should look like "dd MMM yyyy"
Try:
or you could use the
[DisplayFormat]
attribute on your view model:and in your view simply: