Hi There,
I have a fairly large MVC Project I have been working with for some time. Suprisingly I have only just created an action with nullable date time parameters, IE:
public ActionResult MyAction(DateTime? startDate, DateTime? endDate)
Now when I pass a date formatted for the UK these parameters are NOT populated. When the date is formatted for the US they are.
If I pass a UK formatted date that is compatible with the US format the parameter is populated but the month/day are switched round.
In the UK and most of Europe dates are listed Day/Month/Year. IE: 20th Aug 2009 is 20/08/2009 NOT 08/20/2009 as it is un the US.
So:
.../MyAction?startDate=01/01/2009
Works and I get first of Jan 2009.
.../MyAction?startDate=13/01/2009
Fails - start date parameter is empty.
.../MyAction?startDate=05/01/2009
Fails - start date parameter is populated but with 1st May 2009, when it should be 5th Jan 2009.
It's pretty easy to guess what is happening here. For some reason the ASP.NET MVC framework is not picking up the locale when attempting to parse the date. Is this a known bug? If so is there a planned fix?
I have got round this for now by hacking the action so the dates are string parameters that I then parse myself... Smells bad as you can imagine so I would love a fix for this please...
Thanks.