Ilya Khorev
Ilya Khorev

Reputation: 41

mvc3 unusual routing

I have two routes except for default:

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

The first route works perfectly, links like .../Shop/3/Index, .../Shop3/Messages are correctly processed.

But for the second route - links like .../Shop/3/List/5 are not found. Anyone know why?

Upvotes: 0

Views: 67

Answers (1)

Mark Oreta
Mark Oreta

Reputation: 10416

Your more explicit route should be first, the routing engine is attempting to match Shop/Id/Action in ShopDefault and then probably failing and giving you a 404 before it gets to your more explicit route of Shop.

You should put the routes in the opposite order:

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

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

Upvotes: 3

Related Questions