//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相关文件夹:
3. 在Area的Views目录下的_ViewStart.cshtml文件中, 指定Area的默认模板
4. 创建Area的Controller类:
[Area("Admin")]
public class HomeController: Controller
{
public IActionResult Login()
{
return View();
}
}
5. 创建_Layout.cshtml及View文件.