欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-14 18:20:37
写博客原因:添加了区域(用作后台)后,报错: An unhandled exception occurred while processing the request.AmbiguousActionException: Multiple actions matched. The following ......

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

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 区域路由设置(配置)

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

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

代码如下:

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 区域路由设置(配置)