0

I am having some culture specific issue with post action method. I have a post action method which is working fine when i am dealing with french, russian, urdu, or japanese. But when I am going with the es-MX(spanish culture) and ar-AE(culture); I am getting some problem. I have date field in Model class during get method is getting set properly, but when the model object is getting passed to the post method, the value of the date field is lost somehow and value i am getting in date field is 01/01/0001. I don't know why this is happening. If there's some problem with the code, then it should also not work for the french, russian culture as well.

Do you guys have any idea on this?? any code suggestions are appreciated.. Thanks

  • Are you formatting datetimes in the form based upon the client culture? – VJAI Jul 14 '12 at 13:58
  • I am overriding the OnActionExecuting method and applying the culture code to the current thread. – kaustubh shukla Jul 14 '12 at 15:19
  • Are you getting any validation errors? please post some code if you can. – VJAI Jul 14 '12 at 16:24
  • I am not getting any validation errors, but in action method when I am using ModelState.IsValid; it is giving me false. I guess it's because of this date issue. Code is real big in size, about 50-60 lines; Which section of code you want me to post? – kaustubh shukla Jul 15 '12 at 03:01

1 Answers1

0

The default model binder does the validation based upon the current culture of the server. You are setting the culture in the action filter and the default model binder is invoked before the action filter execution so the validation fails.

One way I can see to solve this problem is setting the culture for the current thread before the default model binder is invoked (i haven't tried this so i can't assure whether this work or not) the other option is you can go for custom model binder.

Community
  • 1
  • 1
VJAI
  • 32,167
  • 23
  • 102
  • 164