0

So I currently have a weird issue with date formatting in my ASP.net MVC5 application. I have the following settings applied:

Web.config

<globalization culture="nl-BE" uiCulture="nl-BE" />

Data model

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

and even in my Controllers I've tried setting Culture and UICulture manually.

When I debug this on my local machine (Win 10, ENG/US configured) it shows dates as expected. As well on chrome as Edge or Firefox.

However, when I publish this site to my server (Win 10 pro, english with nl-BE keyboard layout). And then browse to this site from this server (localhost). IE and Firefox show the datepicker in the right format. Chrome however defaults to mm/dd/yyyy. I've tried tinkering with every setting I could think of but I can't get chrome to display the date in the correct format. Does anybody have any idea?

For reference, my headers from server vs. those on my development machine:

Dev machine

Response headers
Cache-Control:private, s-maxage=0
Content-Encoding:gzip
Content-Length:3470
Content-Type:text/html; charset=utf-8
Date:Fri, 25 Sep 2015 22:03:35 GMT
Server:Microsoft-IIS/10.0
Vary:Accept-Encoding
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:5.2
X-Frame-Options:SAMEORIGIN
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?QzpcVXNlcnNcR2xlbm5cRG9jdW1lbnRzXEJhZXJ0XEJhZXJ0TVZDNQ==?=

Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:__RequestVerificationToken=gRwm97zFECc_tLmXiIZGLn1g3gZo36Gk_zT6ufrkC00FlKkszN0gsVT7nt6z4KTu9_EiXTHo4qL27GDLmIHCpo-awOP39KyI9PU5eI5JkQU1; .AspNet.ApplicationCookie=SvY0ygIeVi2w8Y2K4TeLgFBbx0VXKi0YaVC7vsEG2iRq9vqt_rPySPNYH9YxZcd0sLFFld1Ue6pdfElWB44yfM4wGSUUkuCJckntXy8JhIYfgOSRyeBBi_DzLykA_Jjypjr3Wd6GsSZbhQ6SnMpGqhKwJlC-6jZCaszmWf4jCoXr5JsQWL-A-XyNcNl5au4PwqQR0PtcHaHi1b-xhEzWECBDYg7MxsCpA_3ogUowON9ftn5fXUFI1VuTCgCHuhytWOeDczPUnATZjcD1Qg1oxwFfZRD9faFarqLGj3lJ1XxvkudSW8mL_aBwcEznPcTUgEt6QYpMVvuQfbxNPpdFnOUIs7epuxo6EmGOf7tIy9iRyMSMXeJA15i_G6CkyhsWaZOjHl-T1rTHCIpsqJ7_iJK-ZpPvcVEU_c3VnyCJdHTc7dOj-mRlMiuW7Ng4Qd7trRZGecv3-aGrAMdGGKW9uShhOm6Y4LbAIhjItRQ4dZQ1QU4tK4JK4KCI2axh6dm37Tzyu-DPVzG9W_BZox5fZw
Host:localhost:58980
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36

Server machine

Response headers
Cache-Control:private, s-maxage=0
Content-Length:13449
Content-Type:text/html; charset=utf-8
Date:Fri, 25 Sep 2015 22:05:49 GMT
Server:Microsoft-IIS/10.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:5.2
X-Frame-Options:SAMEORIGIN
X-Powered-By:ASP.NET


Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:nl,en-US;q=0.8,en;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Cookie:__RequestVerificationToken=n-pWZRH9H-43UCQr45yiz7VoWt_yAN5HNmH_QgfPVhWio1j3qs5M7ytBgJPyJCLMQeSB-ijuC0FK_51MwOEXYvPZ-Wv-MpWCQWSRb0AUOMc1; .AspNet.ApplicationCookie=Te7ClXd741mhPk4hrU0YG-CFiOnnLVcbjN7so8m0JT6R-vBQKhCFQ2vSScqsyIb0Q7gYL10Q2zpB3OA492y8dtu20PT7wvbelYYo3iVWlpMPAHfV-3dG7KTpb1W4jMT0-3o0OVXz6Dt_MZLT8yaxmykbNYl5rmIERkHH5dWiw-J-IDlpi3zzmWFT8a7SqiC661poDiQUqhNePaSKAEPQ_zY1lwJ0-_6cEK8HwgitA-61ez1rHp_PP0XjjVY0h9l29MivAqu77bWgj9pZDcPAqd9M2Iaez5sW6_qzo5aRhsEEZZvS2zjOF-8SpG0-4uZnrqma3VpU3_upj5PawLlwzoJsXeI89v9Lafd-9V5TegTMr0n6A0Zjyd7Zrz-tYrgqZfxekEIVh7odrAZkfbjDaQE1NU9UCFUYsX5N8ObD5YbEI0_pzkRIK-hvBmGEKCdS3xE6l79LCUOc8G4m0RrmI9BukKg1E6iMjX8w-LoxOPMqLCW4yPtH-bhpwqn91nMz
Host:localhost
Referer:http://localhost/Invoices/Details/ba143e9b-fabc-44c6-abe1-a51e00b0a8bb
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36

EDIT: I've seen the other questions, none of those explain why it would work on machine A and wouldnt on machine B...

Glenn Vandamme
  • 1,146
  • 8
  • 23
  • That question may have the answer to this, but it's hardly a duplicate. – sovemp Sep 25 '15 at 22:39
  • @sovemp, Of course its a duplicate. Read the answer. OP is using the wrong format for the date. It needs to be `DataFormatString = "{0:yyyy-MM-dd`}, `not DataFormatString = "{0:dd/MM/yyyy}` –  Sep 26 '15 at 00:31
  • @Stephen Muecke, I did read the answer. As stated, the format string yyyy-MM-dd could be the answer, as in it , but the questions are different. OP specifically asks why the behavior is different across browsers (behavior which I have confirmed), whereas the question you link makes no mention of this. Looks like the question you linked to asks why it breaks when the TextBoxFor helper is given a date, but again makes no mention of browsers. – sovemp Sep 26 '15 at 04:05
  • Also, @Glenn Vandamme, I believe your question is a duplicate actually, but of this question which should have your answer I believe: http://stackoverflow.com/questions/12633471/mvc4-datatype-date-editorfor-wont-display-date-value-in-chrome-fine-in-interne – sovemp Sep 26 '15 at 04:06
  • @sovemp, Read i again. It clearly states that `` is **only supported in Chrome** (which is why its different in Chrome). IE and FireFox, do not support `type="date"` and all that is rendered is a standard textbox whereas Chrome renders its HTML5 datepicker control which requires the format to be `yyyy-MM-dd` (in accordance with the HTLM5 specifications) which in turn will then display it in the current browsers culture format –  Sep 26 '15 at 04:31
  • @StephenMuecke This still doesn't explain why it works on chrome on pc A correctly, and incorrectly on chrome on PC B. Both on the latest version (45.0.2454.101) – Glenn Vandamme Sep 26 '15 at 11:41

0 Answers0