Default model binder in MVC Defaultmodelbinder

Source: Internet
Author: User

One, off-topic

Continuation of the previous article:

The process of binding an action parameter in MVC

 Public imodelbinder defaultbinder{    get    {        if (thisnull         {            thisnew   defaultmodelbinder();        }         return  This . _defaultbinder;    }     Set     {        this. _defaultbinder = value;    }} 
Second, analysisDefaultmodelbinder
 Public class defaultmodelbinder:imodelbinder{ Object bindmodel (ControllerContext controllercontext, Modelbindingcontext BindingContext){}//Other methods we are not distracted for the time being, more than this method}
 Public Virtual ObjectBindmodel (ControllerContext controllercontext, Modelbindingcontext bindingcontext) {EnsureStackHelper.Ens            Urestack (); if(BindingContext = =NULL)            {                Throw NewArgumentNullException ("BindingContext"); }            BOOLFlag =false; if(!string. IsNullOrEmpty (bindingcontext.modelname) &&!BindingContext. Valueprovider.                Containsprefix (Bindingcontext.modelname)) {//valueprovider is an example of Ivalueprovider, let's analyze it below. if(!bindingcontext.fallbacktoemptyprefix) {return NULL; } BindingContext=NewModelbindingcontext {modelmetadata=Bindingcontext.modelmetadata, Modelstate=bindingcontext.modelstate, PropertyFilter=Bindingcontext.propertyfilter, Valueprovider=Bindingcontext.valueprovider}; Flag=true; }            if(!flag) {                BOOLFlag2 =defaultmodelbinder.shouldperformrequestvalidation (ControllerContext, BindingContext); Iunvalidatedvalueprovider Arg_9b_0=Bindingcontext.unvalidatedvalueprovider; BOOLSkipvalidation =!Flag2; Valueproviderresult value=Arg_9b_0.getvalue (Bindingcontext.modelname, skipvalidation); if(Value! =NULL)                {                    return  This.                Bindsimplemodel (ControllerContext, BindingContext, value); }            }            if(!bindingContext.ModelMetadata.IsComplexType) {return NULL; }            return  This. Bindcomplexmodel (ControllerContext, BindingContext);}

Look at ivalueprovider .

     Public InterfaceIvalueprovider {/// <summary>Determines whether the collection contains the specified prefix.</summary>        /// <returns>True if the collection contains the specified prefix; otherwise, false.</returns>        /// <param name= "prefix" >The prefix to search for.</param>        BOOLContainsprefix (stringprefix); /// <summary>retrieves a value object using the specified key.</summary>        /// <returns>The value object for the specified key.</returns>        /// <param name= "key" >The key of the value object to retrieve.</param>Valueproviderresult GetValue (stringkey); }

Take a look at this blog post: http://www.cnblogs.com/artech/archive/2012/05/17/value-provider-01.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.