I have a MVC action that takes one of its parameters a DateTime and if I pass “17/07/2012” it throws an exception saying that the param is null but cannot have a null value but if I pass 01/07/2012 it is parsed as Jan 07 2012.
I’m passing the dates to the ajax call in DD/MM/YYYY format, should I rely on MM/DD/YYYY format despite the configured culture in web.config?
This is a simple method and there is just this one date parameter.
You got three safe options to send date parameter in Asp.NET-MVC:
YYYY/MM/DDit’s the ISO standard for international dates.Use
POSTrequest instead ofGETrequest.If you want to change the way the default
Model Binderbinds dates:you can change the default model binder to use the user culture using IModelBinder
And in the Global.Asax write:
Read more at this excellent blog that describe why Mvc framework team implemented a default Culture to all users.