Date formatting works in Chrome and does not work in Internet Explorer, or vice versa, with MVC C #

5

If I use it in the template

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd'/'MM'/'yyyy}")]
public DateTime data { get; set; }

It works fine in IE but does not work in Chrome . When I open the edit form, instead of the date appears, dd/mm/yyyy appears. 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; }

It works fine on Google Chrome , but not I.E . the date appears as 2015-08-10 , for example ...

How can I do to 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 it works for both of us ... the problem is that it gets the time, in the format. Ex: "06/15/2015 00:00:00"

If I use

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]

Resolves the problem in Internet Explorer ... but in Chrome it displays dd / mm / yyyy

I do not know what else to do ... does anyone have an efficient solution?

Thank you!

    
asked by anonymous 18.05.2015 / 17:10

1 answer

1

Try:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
    
19.05.2015 / 18:58