Model binding is the process of preparing a list of parameters for a target action method, so the description of the parameter is the core of the model binding. In the ASP.net MVC application Programming interface, the parameter metadata that serves the model binding is represented by the Parameterdescriptor type, and the Actiondescriptor The GetParameters method returns a Parameterdescriptor array.
As shown in the following code fragment, Parameterdescriptor also implements the ICustomAttributeProvider interface to provide attributes that apply to the corresponding parameters. The Parameterdescriptor read-only property actiondescriptor represents the Actiondescriptor object that describes the action method in which it is located. The properties parametername, ParameterType, and DefaultValue represent the name, type, and default value of the parameter, respectively.
1:public Abstract class Parameterdescriptor:icustomattributeprovider
2: {
3: Public virtual object[] GetCustomAttributes (bool inherit);
4: Public virtual object[] GetCustomAttributes (Type attributetype, bool inherit);
5: Public virtual bool isdefined (Type attributetype, bool inherit);
6:
7: Public abstract actiondescriptor actiondescriptor {get;}
8: Public abstract string parametername {get;}
9: Public abstract Type parametertype {get;}
: Public Virtual object defaultvalue {get;}
11:
: Public Virtual Parameterbindinginfo bindinginfo {get;}
13:}
Parameterdescriptor's read-only property bindinginfo the System.Web.Mvc.ParameterBindingInfo object that encapsulates some information to control the binding behavior of the requested data and parameters. As shown in the following code snippet, the abstract class Parameterbindinginfo has four properties, where the Modelbinder object returned by the Binder property of type Imodelbinder is the core of the entire model binding. We will introduce them separately in the next section of this chapter.
1:public Abstract class Parameterbindinginfo
2: {
3: Public virtual Imodelbinder Binder {get;}
4:
5: Public virtual icollection<string> Include {get;}
6: Public virtual icollection<string> Exclude {get;}
7: Public virtual string Prefix {get;}
8:}
If the parameter type is a complex type, all of its public writable properties are bound by default, and the properties include and exclude for the two icollection<string> types represent a list of property names that display settings for participating/not participating in bindings. By default, the request data and parameters are strictly bound by name, but sometimes the request data name has a corresponding prefix, which is reflected on the Parameterbindinginfo prefix property.