回答

2

像这样的东西应该工作:

public class CustomModelBinder: DefaultModelBinder 
{ 
    protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext) 
    { 
     base.OnModelUpdated(controllerContext, bindingContext); 
     //You now have access to "bindingContext.Model" which is your model. 
    } 
} 

然后在Globals.asaxApplication_Start(不要忘记这部分):

ModelBinders.Binders.DefaultBinder = new CustomModelBinder(); 
1

尝试使用自定义模型活页夹。这将在模型验证之前拦截请求管道。实施IModelBinder

+0

这只适用于特定型号,不适用于所有型号。 – Sergey 2014-11-09 10:21:29

相关问题