无法从ASP.NET Core MVC 3.1中的Manage区域路由回去

问题描述 投票:0回答:1
  1. 我为常规客户和相关控制者提供了一个默认的普通未命名区域:Conrollers。在Controllers forlder中,我的控制者上没有任何与区域相关的属性。
  2. 另外,我在区域\管理\控制器文件夹中有“管理”区域,其中包含与用户管理相关的控制器。
  3. 我在“管理”区域中的控制器具有属性:[Area(“ Manage”)](我认为这属于:“常规路由和基于属性的路由不能混合使用。在这种情况下,后者会获胜”,但不确定如何解决这个)。
  4. 这里是Startup.cs的摘录:
           app.UseEndpoints(endpoints =>
            {

                endpoints.MapControllerRoute(
                    name: "areas",
                    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

                endpoints.MapControllerRoute(
                    name: "categoryFilter",
                    pattern: "product/{action}/{category?}",
                    defaults: new { controller = "Product", action = "List" });

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapRazorPages();
            });
  1. 为了解决我的问题,我需要更改什么我能够正常浏览该站点,直到获得与控制器相关的视图,这些视图已被标记为“管理”并放置在“管理”区域中。当我点击这些视图时,所有其他标准视图都将收到“ / Manage /”路径,而我无法返回它们:最初的住所是:https://localhost:12345/,联系人是https://localhost:12345/Contact但随后变为:https://localhost:44311/Managehttps://localhost:12345/Manage/Contact
asp.net-mvc asp.net-core routes asp.net-mvc-routing
1个回答
1
投票

[使用Url.RouteUrl()或Url.Action()时,您未在路线数据中指定area属性,它停留在最新区域,例如(在管理/测试时):

@Url.Action("Index", "Home"); //returns /Manage
@Url.Action("Index", "Home", new { area = "" }); //returns /
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.