Model Binding
The Model binding (binding) is simply the assignment of the action parameter by traversing the data obtained by the Valueprovider (value provider).
In the course of this tutorial, you should have a basic understanding of model binding.
Defaultpropertybindingpredicateprovider
Defaultpropertybindingpredicateprovider: Provides an expression-based method to provide the included properties.
Public classDefaultpropertybindingpredicateprovider<tmodel>: IpropertybindingpredicateproviderwhereTModel:class { PublicDefaultpropertybindingpredicateprovider (); Public Virtual stringPrefix {Get; } Public VirtualFunc<modelbindingcontext,string,BOOL> PropertyFilter {Get; } Public VirtualIenumerable<expression<func<tmodel,Object>>> Propertyincludeexpressions {Get; } }
This class has three properties:
Prefix represents the prefix name
PropertyFilter: Attribute Filtering
Propertyincludeexpressions: properties include expressions
To see how to use the instance code
Private classExcludeuserpropertiesatparameter:defaultpropertybindingpredicateprovider<user>{Func<modelbindingcontext,string,BOOL> _defaultfilter1 =(context, PropertyName)=false; PublicExcludeuserpropertiesatparameter () {} Public Override stringPrefix {Get { return "User"; } } Public OverrideIenumerable<expression<func<user,Object>>>propertyincludeexpressions {Get { yield returnm =M.registerationmonth; yield returnm =M.username; } } }
Controller
Public class Bindattributecontroller:controller { public User echouser ([Bind (typeof(excludeuserpropertiesatparameter))] User User) { return user; }
User entity
Public classUser {[Required] Public intId {Get;Set; } Public intKey {Get;Set; } [Required] Public stringRegisterationmonth {Get;Set; } Public stringUserName {Get;Set; } PublicAddress Address {Get;Set; } }
The Prefix prefix name is user, which means that the request ID must be prefixed with the user
Propertyincludeexpressions: attributes include:
Get
{yield return m = m.registerationmonth; yield return m = = m.username;}
Representation: This property of the detachment is assigned a value.
Let's look at the PropertyFilter effect.
Private classExcludeuserpropertiesatparameter:defaultpropertybindingpredicateprovider<user>{Func<modelbindingcontext,string,BOOL> _defaultfilter1 =(context, PropertyName)=false; PublicExcludeuserpropertiesatparameter () {} Public Override stringPrefix {Get { return "User"; } } Public OverrideFunc<modelbindingcontext,string,BOOL>PropertyFilter {Get { return_defaultfilter1; } } }
_defaultfilter1 expression always returns false
All are not assigned,
PropertyFilter:
Propertyincludeexpressions equals null PropertyFilter will return true by default.
Fromqueryattribute
Fromrouteattribute
Fromformattribute
ASP. Vnext modelbinding