【发布时间】:2013-08-02 18:20:53
【问题描述】:
我有一个使用 asp.net MVC 4 构建的 Web 应用程序。 我想要以下 3 种类型的路线:
- /动作
- /action/id
- /id/id2
在 global.asax 中,我将路线更改如下:
routes.MapRoute(
name: "Without Action",
url: "{id}/{id2}",
defaults: new { controller = "Home", action = "City_Category" },
namespaces: new[] { "Namespace.Controllers" }
);
routes.MapRoute(
name: "Without Controller",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Namespace.Controllers" }
);
但是当我尝试 {action}/{id} 时,它会转到 global.asax 中定义的第一条路线。仅当 url 为 {action} 或 {id}/{id2} 时才有效。
我怎样才能使所有 3 条路线都工作?
谢谢!
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-routing global-asax