5
If I wear the model
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd'/'MM'/'yyyy}")]
public DateTime data { get; set; }
Works perfectly on I.E. but doesn’t work on Chrome
. When I open the Edit form, instead of the date, it appears dd/mm/yyyy
. I can edit and the change is saved. But the value does not load in the edit form when opened.
If I change to
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime data { get; set; }
There it works perfectly on Google Chrome
, but in the I.E
. the date appears as 2015-08-10
, for example...
How can I make it work equally in both browsers, with the format dd/MM/yyyy
?
If I use
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
generates the error: System.Formatexception: The input string was not in an incorrect format.
If I use Html.Textboxfor instead of Html.Editorfor works both... the problem is that it gets time, in format. Ex: "06/15/2015 00:00:00"
If I use
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
solves the problem in Internet Explorer... but in Chrome it displays dd/mm/yyyy
I don’t know what else to do... someone has an efficient solution?
Thank you!
[Displayformat(Applyformatineditmode = true, Dataformatstring = "{0:dd/MM/yyyy}")]
– Vanderson Ramos
You are using
Html.EditorFor
orHtml.TextBoxFor
?– Leonel Sanches da Silva
Take a look at the final HTML being generated, probably the MVC is generating some kind of
<input type="date">
which is not supported by Internet Explorer.– Wédney Yuri
Vanderson, [Displayformat(Applyformatineditmode = true, Dataformatstring = "{0:dd/MM/yyyy}")] generates the error: System.Formatexception: The input character string was not in an incorrect format.
– Felipe Bulle
Gypsy, I was using Editorfor... with the tip of Vanderson and using Html.Textboxfor worked on both... the problem is that it got time in the format. Ex: "15/06/2015 00:00:00"
– Felipe Bulle
Wedney... really has a type=date in the final Html... how can I avoid this?
– Felipe Bulle
@Felipebulle the attribute
type
of his field inChrome
is like date? If the answer is yes, this is the problem. The field mask overrides the value when it is not in the format that the field accepts. For example, if the date is01/02/2016
it must be passed to the field with the attributetype=date
in American format02-01-2016
. Maybe in theIE
he understands by not understanding thetype=date
and interpret astype=text
– Richard Dias