在MVC Asp.net上可能有多个路由

问题描述 投票:0回答:1

我想问一问,是否可能在RouteConfig类中具有多个路由。我的逻辑如下,我想要实现。我已经有actionLink(“ Dashboard”,“ Account” .....),并且希望拥有一个唯一的页面加载时不会与现有的冲突。请帮我有办法。

namespace ContentManagementSystem  
{  
    public class RouteConfig  
    {  
        public static void RegisterRoutes(RouteCollection routes)  
        {  
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  

            routes.MapRoute(  
                name: "Default",  
                url: "{controller}/{action}/{id}",  
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } // I already have this working fine  

defaults: new { controller = "Dashbaord", action = "_Index", id = UrlParameter.Optional  // I want to have seperate, but unique route for this controller for actionResult  

            );  


        }  
    }  
}
c# asp.net-mvc
1个回答
0
投票

将其添加到默认路由的顶部:

namespace ContentManagementSystem  
{  
    public class RouteConfig  
    {  
        public static void RegisterRoutes(RouteCollection routes)  
        {  
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  

            routes.MapRoute("other_route", "other_route/",
               defaults: new { controller = "OtherController", action = "OtherAction" });

            routes.MapRoute(  
                name: "Default",  
                url: "{controller}/{action}/{id}",  
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } // I already have this working fine  

defaults: new { controller = "Dashbaord", action = "_Index", id = UrlParameter.Optional  // I want to have seperate, but unique route for this controller for actionResult  

            );  


        }  
    }  
}
© www.soinside.com 2019 - 2024. All rights reserved.