.net core mvc 区域路由设置(配置)

写博客原因:添加了区域(用作后台)后,报错:

An unhandled exception occurred while processing the request.
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

CompanyHome.Controllers.HomeController.Index (CompanyHome)
CompanyHome.Areas.Manage.Controllers.HomeController.Index (CompanyHome)

不是很明白,大概是找不到进入那个路由吧,命名空间冲突。

总览:

一.>>先在Startup.cs中添加对区域路由的路径,如图红框内

代码如下:

routes.MapRoute(
                    name: "areaname",
                    template: "{Manage:exists}/{controller=Home}/{action=Index}/{id?}");
                routes.MapAreaRoute(
                    name: "Manage",
                    areaName: "Manage",
                    template: "Manage/{controller=Home}/{action=Index}"
                    );

二.>>然后再给区域控制器添加如下:

 

posted @ 2018-08-28 13:57  猪翔heart  阅读(3346)  评论(2编辑  收藏  举报