简体   繁体   中英

How to organize a .NET MVC application in Visual Studio

I am starting to create a complete application in Visual Studio (.NET MVC). Does it makes sense if I put everything into a single solution and create three separate projects: Admin (used by staff to manage the app data), Web (public facing web pages), Shared (common data access and other code). This seems to make sense as later I might add a project for Mobile or an API or ...

If not, how do you structure your solutions/projects in Visual Studio?

If it were me, I'd have everything in one project and use areas to separate my views and models.

Example,

Project
    Areas
        Admin
            Controllers
                AdminController.cs
            Models
                Admin.cs
        Main
            Controllers
                MainController.cs
            Models
                Main.cs
                LoginLogout.cs
                LoginForm.cs
    Views
        Admin
            Shared 
                permissions.cshtml
                admin.cshtml
        Main
            Shared
                loginLogout.cshtml
                loginForm.cshtml
            master.cshtml
            Index.cshtml

Walkthrough: Organizing an ASP.NET MVC Application using Areas

Areas provides a really nice way to section off pieces of your web application, and because it's all in the same project you can have all your sections use the same View Layout (Master Page) to make it all look the same from section to section.

Areas will map to urls like http://somesite/main/index http://somesite/admin/manage/index

In that example, you would not put your main section in an area, instead use normal model view controller patterns for the main part of the site, and only introduce an area for admin or other sections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM