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
将DataFormatString更改为{0:d}
[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.