//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://i-blog.csdnimg.cn/blog_migrate/66ca5aedd15a6dd2301ee64cb7f82830.png)
3. 在Area的Views目录下的_ViewStart.cshtml文件中, 指定Area的默认模板
![](https://i-blog.csdnimg.cn/blog_migrate/2dbf51b9905b7124a93eb2a9aaab13e3.png)
4. 创建Area的Controller类:
[Area("Admin")]
public class HomeController: Controller
{
public IActionResult Login()
{
return View();
}
}
5. 创建_Layout.cshtml及View文件.