Просто подумал о другом решении этой проблемы.
Я считаю, что это намного элегантнее, чем другое решение , и оно основано на атрибутах (хотя это зависит от того, как вы хотите прикрепить это связующее к вашей модели).
Вы можете создать собственное связующее для модели и извлечь его из DataAnnotationsModelBinder
. Затем установите культуру перед тем, как сказать базовому классу связать модель.
public class CustomModelBinder : DataAnnotationsModelBinder {
public override object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext) {
//set the culture
return base.BindModel(controllerContext, bindingContext);
}
}
//and the action
public ActionResult Foo([ModelBinder(typeof(CustomModelBinder))]SomeModel m) {
return View();
}
//Or if you don't want that attribute on your model in your actions
//you can attach this binder to your model on Global.asax
protected void Application_Start() {
ModelBinders.Binders.Add(typeof(SomeModel), new CustomModelBinder());
RegisterRoutes(RouteTable.Routes);
}