Çözüm olarak model binding olmadan önce currentculture ve currentuiculture bilgileri set edilmeliymiş. Dil atamayı yeni attribute tanımı ile sağlamıştım, ancak IAuthorization arayüzünü kullanarak model binding olmadan önce atama yapılması sağlanmış oluyor.
The model binder uses the
CurrentCulture
, not the CurrentUICulture
when parsing dates. Also you haven't shown the code of this CultureAwareAction
but chances are that it executes after the model binding so you are setting the culture too late.
If you want to ensure that it executes before model binding you could implement the
IAuthorizationFilter
interface:public class CultureAwareActionAttribute : ActionFilterAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
// That's for displaying in the UI, the model binder doesn't use it
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX");
// That's the important one for the model binder
Thread.CurrentThread.CurrentCulture = new CultureInfo("es-MX");
}
}
Kaynak:
http://stackoverflow.com/questions/11022745/how-do-i-enforce-proper-globalization-behavior-for-view-models-containing-date-p?rq=1
http://stackoverflow.com/questions/7202607/mvc3-globalization-need-global-filter-before-model-binding?rq=1
http://stackoverflow.com/questions/10156154/net-mvc-international-dates-model-validation-from-posted-form
http://stackoverflow.com/questions/6629406/mvc3-globalization-not-set-for-modelstate-value-culture
Hiç yorum yok:
Yorum Gönder