.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)

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

总览:

.net core mvc 区域路由设置(配置)_第1张图片

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

.net core mvc 区域路由设置(配置)_第2张图片

代码如下:

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

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

.net core mvc 区域路由设置(配置)_第3张图片

 

转载于:https://www.cnblogs.com/zx3180/p/9547834.html

你可能感兴趣的:(.net core mvc 区域路由设置(配置))