MVC Region Summary

Source: Internet
Author: User

MVC3 has been learning, the project sometimes will be used, blog park has been wandering, want to write something, but I am usually lazy, the theoretical level of things they do not write, or to point to the actual simple entry of the blog, to their own summary of the ability is a promotion, of course, also hope that the people have not used the region has helped.

Why do we have a zone?

MVC itself advocates the separation of concerns, controller control business logic, the model is used to read data, depending on the display display page, so whether for developers themselves or for later maintenance project developers are very good, can open familiar with the project business, and not like the hierarchy is not clear, code is not standard, A logically chaotic project that boosts development efficiency. But when the business logic of the project itself is complex enough, if all the business logic is written under the Controller folder, you will see a very large variety of named controllers, this time the role of the area is displayed, you can a business logic corresponding to a folder, very practical , simple and clear.

How do I write an area?

Right-click your own MVC project, add-zone, write your own zone name, and the result is as follows:

The generated login folder under areas, and help us generate a LoginAreaRegitrations.cs class file, what is the role of the next, the first set up Logininfo controller to see the effect:

How do I handle domain controller names?

If you set up a home controller under the Controller folder under the zone controllers, if there is also a home control controller this time will conflict if:

The solution is simply to add a controlled namespace to the Registerarea method in the LoginAreaRegitrations.cs that we saw just now in the area control.

It is also possible to add a corresponding namespace at the relative routing location by a different name.

The code itself is very simple to write, really if written blog or need to take some time, contact is quite a lot of things, the advanced of their own at present can not write, their own nothing to write the basics of things, exercise their own at the same time also hope to help everyone ~ Monday good mood ~

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.