asp.net Mvc new beta feature automatic binding (1)-Experience Chapter

Source: Internet
Author: User
Tags datetime

We know that the new Modelbinder feature is added to the ASP.net Mvc Preview5, which is very powerful, but not so friendly to use, so in the latest ASP.net MVC beta, the framework further strengthens this part , so that the automatic binding of complex parameters can be realized, this paper will fully explore the modelbinder implementation of the whole MVC framework and fully excavate the modelbinder ability of the system, so that the Web development based on MVC framework can get rid of the misery of the page value.

(See also: Http://www.cnblogs.com/leven/archive/2008/08/31/1280481.html and http://www.cnblogs.com/leven/archive/2008/09 /01/1280862.html)

First, let's review the use of Modelbinder. First, define an entity class, and then write a modelbinder for that class to determine the binding, so you can use it directly in the action arguments.

However, many friends have realized that this modelbinder is too complicated to use. Is there a better solution? In asp.net Mvc beta, the answer is yes. That's the new feature available in beta, automatic binding.

We know that in preview5, the system can also automatically bind to basic types as well as DateTime and nullable<datetime>, but there is nothing for custom classes to do. But think about it, custom entity classes should also be made up of a series of simple types. , that is, a complex entity class is composed of many simple types, is there a common way to do this binding? The answer is yes, in fact, in my last article on PREVIEW5 binding, the example is to provide a relatively simple universal binding scheme, of course, We can extend this program to make it more intelligent and want to asp.net the MVC development team is aware of this, so in the latest beta release, the MVC framework enhances the functionality of the Defaultmodelbinder, making the binding work as simple as possible.

In this article, we'll explore how the new Modelbinder works, and how it does it.

First of all, we use the fastest way to do a "new" modelbinder practice, the establishment of an MVC project. Set a default routing. Then start adding code, the project file for this practice is as follows:

After the project was established, we added a SimpleArticle.cs to the NewModelBinderDemo.Library.Entities. This is a simple entity for the test, and the code is as follows:

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.