0

我有两条路线,除了默认:

routes.MapRoute("ShopDefault",
                "Shop/{id}/{action}",
                new { controller = "Shop" });
routes.MapRoute("Shop",
                "Shop/{id}/List/{categoryID}",
                new { controller = "Shop", action = "List"});

第一条路线完美运行,链接如.../Shop/3/Index,.../Shop3/Messages被正确处理。

但是对于第二条路线-.../Shop/3/List/5找不到类似的链接。有谁知道为什么?

4

1 回答 1

3

您应该首先使用更明确的路线,路由引擎正在尝试匹配 ShopDefault 中的 Shop/Id/Action,然后可能会失败并在到达您更明确的 Shop 路线之前给您一个 404。

您应该以相反的顺序放置路线:

            routes.MapRoute(
                "Shop",
                "Shop/{id}/List/{categoryID}",
                new { controller = "Shop", action = "List"},
                new { id= @"\d+" }

            routes.MapRoute(
                "ShopDefault",
                "Shop/{id}/{action}",
                new { controller = "Shop" });
于 2012-09-14T15:35:06.770 回答