);
}
Public Virtual Imodelbinder getbinder (type modeltype, Bool Fallbacktodefault ){
If (Modeltype = Null ){
Throw New Argumentnullexception ( " Modeltype " );
}
ReturnGetbinder (modeltype, (fallbacktodefault)?Defaultbinder:Null);
}
Private Imodelbinder getbinder (type modeltype, imodelbinder fallbackbinder ){
// Try to look up a binder for this type. We use this order of precedence:
// 1. Binder registered in the global table
// 2. Binder attribute defined on the Type
// 3. supplied fallback Binder
Imodelbinder binder;
If (_ Innerdictionary. trygetvalue (modeltype, Out Binder )){
Return Binder;
}
Binder=Modelbinders. getbinderfromattributes (modeltype,
()=>String. Format (cultureinfo. currentuiculture, mvcresources. modelbinderdictionary_multipleattributes, modeltype. fullname ));
ReturnBinder??Fallbackbinder;
}
This is the three reloads of the method, which are called in order. When the third overload method is called, it first tries to get the imodelbinder corresponding to modeltype from the _ innerdictionary variable of modelbinderdictionary (previously mentioned that modelbinders is a static class, therefore, we have the opportunity to add the ing of the type and custom imodelbinder to this dictionary. Otherwise, we will try to get it from attribute again. If none of them can be found, then defaultbinder will be returned, here defaultbinder is an instance of defamodelmodelbinder. Finally, the imodelbinder corresponding to the parameter is declared and determined. Next, the parameter is assigned a value through the imodelbinder. bindmode () method.
2) value assignment
The next thing is that the corresponding imodelbinder plays a role, combines the value with controllercontext. Controller. valueprovider, and assigns a value to the parameter.
....
Then the requested action is officially executed.
Summary:
This article only analyzes a very small clip.ArticleContinue to explore.
The following lists the related classes. If you are interested, refer:
Custommodelbinderattribute, modelbinderattribute, bindattritionary, imodelbinder, defaultmodelbinder, modelbinderdictionary, modelbinders, modelbindingcontext, and xxxdescriptor.