Put controllers, model, and view in MVC into separate projects

Source: Internet
Author: User

Model: New-Project-windows-console Application Mvctest.model

Controller: New-Project-windows-console Application mvctest.bussiness

Views: New-Project-web-asp.net MVC4-Default-Mvctest.web

Install Entifyframework in the solution (installed in all three solutions).

Like layer three, mvctest.bussiness references Mvctest.model

Mvctest.web references Mvctest.bussiness and Mvctest.model

Model Generation: Right-click Mvctest.model-entityframework-reverse Engineer Code first. Once configured, the entity class is generated successfully.

Controller: Add Setup/myroutestable.cs in Mvctest.bussiness

The code is as follows:

 Public Static classmyroutestable { Public Static voidregisterroutes (routecollection routes) {routes. Ignoreroute ("{Resource}.axd/{*pathinfo}"); //Default Routesroutes. MapRoute ("Default",                "{Controller}/{action}/{id}",                New{controller ="Home", action ="Index", id =urlparameter.optional}); }    }
View Code

View: Modify Global.asax in Mvctest.web

protected void Application_Start ()        {            myroutestable.registerroutes (routetable.routes);        }
View Code

Resources:

EF Codefirst generating entity classes http://www.cnblogs.com/jiajinyi/archive/2013/09/02/3295799.html

Project separation: http://blog.csdn.net/cmalaya/article/details/8215256

Put controllers, model, and view in MVC into separate projects

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.