1

What setting in windows determines how the model binder hydrates the model given the datetime coming from the front end as string like this:

27%2F11%2F2012+16%3A09%3A01.21%2F03%2F2013+13%3A51%3A00

In one deployment environment I am getting ModelState.IsValid == false if the first 2 numbers are greater than 12 (i.e. it assumes months rather than days).

4
  • what format is that? is that any standard? Commented Aug 16, 2013 at 14:58
  • It is URI encoded as it comes from the front end ... Commented Aug 16, 2013 at 15:00
  • This decodes to: 27/11/2012 16:09:01.21/03/2013 13:51:00 Commented Aug 16, 2013 at 15:32
  • sure (-: but mvc should take care of this. Commented Aug 16, 2013 at 17:31

1 Answer 1

2

The computer will parse the date based on its region (it is set in the control panel in various places depending on the OS). If your two machines have different regional settings, there will be friction as different regions exress dates different (dd/mm/yyyy in the U.K., mm/dd/yyyy in the U.S.). You can override that setting by configuring your web.config to help with consistency.

<globalization culture="en-US" uiCulture="en-US"/>

Another option I would suggest is to save the value of your web form control in the universal date time format: e.g. Tue, 1 Jan 2008 00:00:00 GMT. This will be parsed correctly irrespective of your machine's region.

Sign up to request clarification or add additional context in comments.

3 Comments

this may help. thanks. it is deployed within ms server 2008 btw.
Are you using a DatePicker on your front end?
had to change entries to en-GB for my scenario

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.