回答

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

相關問題