This is kinda bizarre...
On my form I have two buttons (both are <input type="button" />
). Button 1 (B1) has a onclick="update()"
where calls an Ajax with the Data parameter filled. The second button (B2) uses a old-fashion submit. By the way, both buttons calls the same controller/action. Buttons are there to send back date from a @Html.EditorFor(x => x.StartDate)
field (that is a jquery datepicker).
So, to illustrate, lets say that StartDate = "30/09/2012" (dd/mm/yy).
If I click B1, Ajax is called and all data correctly passed through data parameter. This parameter is a json from a $("#form").serializeArray(). This call skips binders and call directly the specified controller/action works like a charm. My StartDate property comes with the correct date.
But if I click B2, the default behavior builds a query string and my application crashes. I built a custom date binder to intercept and inspect what was going on, and I noticed that the date string was "09/30/2012" and was trying to convert to my culture (pt-BR) where it uses dd/mm.
Going a little further, I saw that the problem was on my submit event, as it was building a bizarre query string:
//../Action?StartDate=09%2F30%2F2011%2000%3A00%3A00
One more thing: Datepicker, webconfig and client browser are all configured to the same culture.
Now, how I should proceed with this? Can I generalize that all dates submitted will arrive on the binder as mm/dd/yy and force my custom date binder to manage this, or am I doing something wrong and forgetting to configure something?
Thanks!