I have a regular form that gets POSTed to a controller. Dates must be entered in the day/month/year format, since it’s an app for South America. I’m force setting the current culture UI to spanish-Peru. Tried with MVC 3 and 4 beta.
Here is the controller Code:
[HttpPost]
public ActionResult Create(EditPatientViewModel model)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-PE");
if (ModelState.IsValid) {
// never reaches in here if date submitted as day/month/year
}
}
When I debug and look at the ModelState errors, the culture inside of them is still set to en-US, even though I can verify the CurrentThread.CurrentUICulture is set to es-PE.
How do I make the ModelState validation also change?
Set the globalization in your web.config to es-PE.
And it should work fine, posting and validation.
UPDATE
If for any reason your ModelState is interpreting your Date incorrect you can do something like:
before the validation occurs.
UPDATE
You can also change default binder and make your own.
Put
in the Application_Start() in the Global.asax.
Regards.