.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}"
                    );

二.>>然后再給區域控制器添加如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM