Experience asp.net Mvc Preview5 (3)-Exploring the workings of Modelbinder

Source: Internet
Author: User

In the previous two articles, we studied the vieweingine improvements of the ASP.net Mvc Preview5, and starting with this article, we began to look at the new features in PREVIEW5: Modelbinder.

First, let's take a look at what is the Modelbinder feature, and what's the use of it, in previous versions, if we were going to get the data in action, there were generally three ways, one through the arguments to the action, but for some reason there was only a simple type of parameter, such as int, string and so on, the second way is to get it through the request, but when there is more data, this way is very difficult. The third is to use the extension method in Bindinghelperextensions, but this way still cannot satisfy our request. Our ideal way is :

If you can write this, you will be able to get the incoming object directly in the parameters. It will make the structure of the program more reasonable. In the new edition, the framework introduces Modelbinder to solve this problem, so that our ideal effect can be achieved.

The role of Modlbinder is to create a conversion relationship between HTML parameters and objects, through the system built-in or user-added binder to complete the conversion process, whenever the action contains parameters, the system will automatically query the URL or whether the form contains the corresponding values, A certain Modelbinder object is then invoked to convert the parameter to the Passed-in value.

Below we analyze the work process of the modelbinder. We know that the execution of the action is actually controlleractioninvoker, and there are some methods in this class that, in the process of execution, It first finds the method that corresponds to the action in controller, and then determines whether methods have parameters and, if there are parameters, assigns them to them in a particular way. This part of the specific code we'll take a look at:

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.