asp.net Mvc new beta feature automatic binding (2)-Deep Exploration Chapter

Source: Internet
Author: User
Tags bind

The basic use of automatic binding is described in the previous article, and in this article, we'll delve into how automatic binding works.

Automatic binding is really an exciting feature, but in order for it to work better in our project, we need to learn more about how to further tune the feature and how it works. And this article is about to uncover this mystery.

In order to better understand this feature, we need to CodePlex to download a asp.net MVC source code and analysis, in this writing, CodePlex has put on the beta version of the source code, if you want to know more friends can download and compare this article analysis.

In the beta release, the feature of automatic binding is added and some modifications are made to the binding features

New Bindattribute: Automatic binding attribute settings

Modifying Defaultmodelbinder: Implementing part of automatic binding

Modify Controlleractioninvoker: Binding Call Entry

New Modelbindercontext, encapsulating the data required for binding

New Binderresult, encapsulating binding results

Other less important changes skipped

We analyze the execution of the binding step-by-step, and we must first see the Getparametervalue method in Controlleractioninvoker:

Here is the attempt to bind parameters by calling Modelbinder for each parameter, and here the Getmodelbinder method is the same as P5, where we can customize the binding in the case of our custom modelbinder. However, when it is automatically bound, it is defaultmodelbinder, and then in the Getpropertyfilter method, a lookup bindattribute is used to get the settings for the binding. Finally, bind the data.

Crucially, we need to analyze defaultmodelbinder, but before that, there is a class that needs to be looked at carefully, and that is Bindattribute, which is used to modify parameters, and it has 4 important properties: Include,exclude , prefix and a method: Ispropertyallowed, which are used to set: Bound fields, unbound fields, parameter prefixes, and determining whether a given field is set to run bindings, and the method acts as a predicate<string> The delegate is marshaled into the Modelbindercontext incoming Bindmodel method.

Now to discuss using the default bindings, first give all the Defaultmodelbinder methods:

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.