【发布时间】:2012-10-10 08:41:53
【问题描述】:
首先,路线如下:
routes.MapRoute("PlaceRoutes", "{b}/Places/Show/{id}/{subaction}",
new { b = "yokota-ab-japan", controller = "Places", action = "Show", id = UrlParameter.Optional, subaction = UrlParameter.Optional }
);
此网址:localhost/yokota-ab-japan/Places/Show/4b5bfc7ef964a520332029e3
不匹配吗,
此网址:localhost/yokota-ab-japan/Places/Show?id=4b5bfc7ef964a520332029e3
会。
事实上,当使用 /id 时,它只是简单地路由回根主页。当我在调试器中运行它时,它甚至从未触及 Places/Show 动作,它只是简单地返回。但是,如果我使用 ?id= 它的路由很好。
我以前从未遇到过这种情况……非常困惑。我尝试使用 Phil Haack 的路由调试器,但由于它甚至没有触及路由,只是循环回到主页,所以调试器没有帮助。
编辑 - 这是完整的路线列表
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("PlaceRoutes", "{b}/Places/Show/{id}/{subaction}",
new { b = "yokota-ab-japan", controller = "Places", action = "Show", id = UrlParameter.Optional, subaction = UrlParameter.Optional }
);
routes.MapRoute("BaseRoutes", "{b}/{controller}/{action}/{id}",
new { b = UrlParameter.Optional, controller = "Home", action = "Index", id = UrlParameter.Optional },
new { controller = "Home|Member|Places|Search|Admin" }
);
routes.MapRoute(
"NullBase",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { controller = "Home|Member|Places|Search|Admin|Auth" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
【问题讨论】:
-
您还定义了其他路线吗?
-
是的,但那条路线是第一位的。我用完整的路线列表更新了问题。
-
您可以发布您的控制器操作吗?在具有此操作的 MVC 3 中: Show(string subaction, string id, string b) 路由对我来说很好
标签: asp.net-mvc routing