2015-08-17 82 views
2

對於下面的代碼,我想知道公司類型由前綴括號[]如何影響參數自定義的模型綁定MVC

public ActionResult SaveEmployee([ModelBinder(typeof(MyEmployeeModelBinder))]Employee e, string BtnSubmit) 
{ 
     // some logic 
} 

回答

3

MyEmployeeModelBinder是自定義模型粘結劑,將在員工執行的,而不是默認的模型綁定即

public class MyEmployeeModelBinder: DefaultModelBinder 
{ 
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { 
    ... 
    } 
} 

的員工類型影響BindModel()bindingContext屬性,如bindingContext.ModelMetadatabindingContext.ModelType,包含有關模型的信息。看看ModelMetaData:https://msdn.microsoft.com/pt-br/library/system.web.mvc.modelmetadata%28v=vs.108%29