简体   繁体   中英

MVC ignores culture settings in web.config

I'm constructing a MVC website in C# for use in Denmark, and I have therefore set the folloving in my web.config files, in the system.web.globalization node: culture="da-DK" uiCulture="da-DK"

When I try to enter the date November 21th. 2018 as 21-11-2018 in a "Html.EditorFor(model => model.Date ..." control where model.Date is a DateTime, I get an error saying: "The field Date must be a date."

If I enter 11/21/2018 it gets accepted as if the culture was "en-US", but as the site is intended for use in Denmark, the dates must reflect that.

I hav found plenty of posts across the internet with the same problem, but non with an answer that solved my problem - 90% says: "Set culture in web.config", but I've done it and it do not work.

What an I missing in order for this to work?

One of possible reasons is as follows: you send GET (not POST) requests to web server.

Your custom culture will be used only for processing of POST requests. For GET requests invariant culture is always being used.

But I would recommend you to post minimal working example here.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM