Asp.net 5 (MVC6) Areas 分区
1. Startup.cs 类的 Configure方法中, 加入Area路由设置代码:
![](https://images2015.cnblogs.com/blog/462334/201602/462334-20160224101953474-1212265249.png)
![](https://images2015.cnblogs.com/blog/462334/201602/462334-20160224101954005-1171028806.png)
//app.UseMvcWithDefaultRoute();
app.UseMvc(routes=> {
// add the new route here.
routes.MapRoute(name: "areaRoute",
template: "{area:exists}/{controller}/{action}",
defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
2. 创建Areas相关文件夹:
![](https://images2015.cnblogs.com/blog/462334/201602/462334-20160224101953474-1212265249.png)
3. 在Area的Views目录下的_ViewStart.cshtml文件中, 指定Area的默认模板
![](https://images2015.cnblogs.com/blog/462334/201602/462334-20160224101954005-1171028806.png)
4. 创建Area的Controller类:
[Area("Admin")]
public class HomeController: Controller
{
public IActionResult Login()
{
return View();
}
}
5. 创建_Layout.cshtml及View文件.