1.右鍵項目新建文件夾 Areas網絡
2.先把項目分類包好,建兩個文件夾,放Controller和View,Model也能夠放在這裏spa
由於項目啓動默認打開的是Home/Index ,我把它放在了Website文件夾內了,這就須要更改路由配置了code
3.若是更改了默認目錄,就要去修改路由配置了,打開Global.asax.cs代碼以下,F12進 RouteConfigblog
using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace Demo.Web { public class MvcApplication : HttpApplication { protected void Application_Start() { // 移除X-AspnetMvc-Version HTTP 開頭 MvcHandler.DisableMvcResponseHeader = true; // 註冊全部Area AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); AutofacConfig.Register(); PermissionUtil.ValidPermissions(); } } }
4.修改RouteConfig,主要修改就是加了 namespaces: new[] { "Demo.Web.Areas.Website.Controllers" } 和 route.DataTokens["area"] = "Website";圖片
using System.Web.Mvc; using System.Web.Routing; namespace AnFund.Web { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); var route = routes.MapRoute("Default", "{controller}/{action}/{id}", new {controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new[] { "Demo.Web.Areas.Website.Controllers" } ); // 更改視圖默認位置 route.DataTokens["area"] = "Website"; } }
來源於網絡路由