Analysis of Binding mechanism of ASP.net mvc:model

Source: Internet
Author: User

Environment:

Windows 2008, VS 2008 SP1, asp.net Mvc RC1

Request Process Fragment:

The Controlleractioninvoker.invokeaction () method is invoked before the requested action is invoked, in which a reflectedactiondescriptor instance is constructed, This instance contains the descriptive information for the action.

Next, the Controlleractioninvoker.getparametervalues () method is invoked, by passing in the Reflectedactiondescriptor instance created before, Gets the action argument list (the corresponding instance of the Parameterdescriptor is created), and then iterates through the parameters, trying to get the value of the parameter, in the loop of the traversal, The Controlleractioninvoker.getparametervalue () method is invoked.

The following is the source code for the Controlleractioninvoker.getparametervalue () method:

Protected Virtual Object Getparametervalue (ControllerContext controllercontext, Parameterdescriptor Parameterdescriptor) {//collect all of the necessary binding properties Type ParameterType = P

            Arameterdescriptor.parametertype;

            Imodelbinder Binder = Getmodelbinder (parameterdescriptor);

            idictionary<string, valueproviderresult> valueprovider = ControllerContext.Controller.ValueProvider; 

String parametername = ParameterDescriptor.BindingInfo.Prefix??

            Parameterdescriptor.parametername;

            Predicate<string> propertyfilter = Getpropertyfilter (parameterdescriptor);

                Finally, call into the binder modelbindingcontext BindingContext = new Modelbindingcontext () { Fallbacktoemptyprefix = (ParameterDescriptor.BindingInfo.Prefix = null),//Only fall back if Prefix not specifie D modelname = parametername, modelstate = COntrollerContext.Controller.ViewData.ModelState, Modeltype = ParameterType, propertyfilt

            ER = propertyfilter, valueprovider = Valueprovider}; Object result = Binder.

            Bindmodel (ControllerContext, BindingContext);

        return result; }

Related Article

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.