I have an MVC4 app which is compiled in the UK and hosted on a US server. In my model I have a date field which is required.
Attached to this field is a date picker, on selecting a date it will set a date to be UK format "DD/MM/YYYY" e.g. 23/12/2013. On submitting the form the application throws a validation error as it does not expect the the format.
In MVC4 how do I:
Has anyone got any details on how to very validation based on globalisation of the user?
Thanks
Did you add the below segment in web.config
?
<globalization
enableClientBasedCulture="true"
uiCulture="auto"
culture="auto" />
and read your date in code as DateTime format. that should not give you a problem.
Another way is to in you server side code read tha date always as DateTimeUTC and when ever you display the date on the screen, use .ToLocalTime()
In the web config, in the globalization section, set the culture to "Auto". this will use user's current culture (including number and Date time format)
<globalization culture="Auto" />
The .net framework will parse and render data according to the user culture and both MVC and Entity will work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With