I have a model Toto with a DateTime Time.
I have a basic controller who can edit Toto.
In the edit view, I can see the date in format : MM/dd/yyyy hh:mm:ss AM(PM)
I store that Time in a database.
But how can I display it in this format: dd/MM/yyyy.
I already found a way, I just add
[DisplayFormat(ApplyFormatInEditMode=false, DataFormatString =
“{0:dd/MM/yyyy}”)]
It works well when i look at all my entries but in the edit mode I have the same basic format (MM/dd…).
So I change :
ApplyFormatInEditMode=true
The format in the edit view is good but when I save it, it tells me that : The value ’30/10/2012′ is not valid for Time.
How can I apply the format in the Edit view ?
Many thanks.
To be clear, I want the format : dd/MM/yyyy and not MM/dd/yyyy
change the DataFormatString to {0:d} as like
[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]