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