Experience asp.net Mvc Preview5 (4)-combat modelbinder, materialized action parameters

Source: Internet
Author: User

In the last chapter, we analyze and understand modelbinder and this article will add our own modelbinder in the example to get the effect we expect. This time we have a simple demo to the whole station of the Modelbinder to do a solution.

First, we give the engineering document diagram:

Note that in this case, my goal is to implement a generic, extensible Modelbinder engine for the entity object of the whole station. Because we want to convert between entity objects and URL strings, we can define the corresponding methods to implement them for convenience, so we define the IEntity interface, The interface is defined as follows:

Explained, the Fill method converts the corresponding string into an object. The ToString method is to convert the object to a specific string. That is, as long as an object implements the interface, We can easily convert the object from the URL string to the object. That's exactly what we're trying to achieve. Another way is to let ientity to achieve iconvertible, but iconvertible method is too much, lazy will not use it.

Then, in the project, BaseEntity is an abstract class that implements only the methods of object and string conversion in ientity. For versatility, here's the reflection. The Fill method implements:

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.