url路由中的静态内容

时间:2013-10-03 14:38:54

标签: asp.net-mvc-4 routing

我有两条路线

   context.MapRoute("",
                "Route1/{controller}/{programid}/{action}"
            );

   context.MapRoute("",
                "Route2/{controller}/{programid}/{action}"
            );

Url.Action(“action2”,“controller2”,new {programid = 123});

结果网址:Route1 / controller2 / 123 / action2

是否可以获得以下网址:

预期网址:Route2 / controller2 / 123 / action2

1 个答案:

答案 0 :(得分:0)

将路线修改为

context.MapRoute("Route1", 
            "Route1/{controller}/{programid}/{action}"
        );

context.MapRoute("Route2",
            "Route2/{controller}/{programid}/{action}"
        );

然后使用Url.RouteUrl之类的

Url.RouteUrl("Route1", YourRouteProperties }

Url.RouteUrl("Route1", new { controller = "YourController", action = "YourAction", 
 programid= "YourProgramId"}}