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
This is solution:
Before ToString() use Value.
Try this in MVC 4.0
The [DisplayFormat] attribute is only used in EditorFor/DisplayFor, and not by the raw HTML APIs like TextBoxFor. I got it working by doing the following,
Model:
View:
Output: 30/12/2011
Related link:
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayformatattribute.applyformatineditmode.aspx
For all the given solution, when you try this in a modern browser (like FF), and you have set the correct model
mvc(5) wil render (the type of the input is set to date based on your date settings in your model!)
And the browser will show
To fix this you need to change the type to text instead of date (also if you want to use your custom calender)
I was not able to get this working entirely based on the suggestions above. Including the DataTypeAttribute
[DataType(DataType.Date)]
seemed to solve my issue, see:Model
View
HTH
Below code will help you