ASP.Net MVC RC1 RouteCollection.MapRoute Problem – Education Career Blog

I have a problem with the RC1 version of ASP.Net MVC. Whenever I add a Route before the “Default” route, the resulting Urls created are for the first Route added.

Here is my Routing in Global.asax.cs

            new { controller = "ProductSubType", action = "Index", id = "" }

            new { controller = "Home", action = "Index", id = "" }  

My Url creation:

        <%= Html.ActionLink("Bikes", "Index", "Bikes") %><br />
        <%= Html.RouteLink("Bikes", "product-detailed", new { controller = "Bikes", action = "Index" }) %>

I would expect the first ActionLink to create a Url like “/Bikes/Index” and the second RouteLink to create “/Products/Bikes/Index”, but both Urls end up as “/Products/Bikes/Index”.

What am I missing here on the routing?



You’re not missing anything. It’s working as designed.

Since the controller and action are both variable in the top route, with no limitations on valid values, then that route is valid for all values of controller and action.

Potential work-arounds:

  • Fix the controller and/or action values so that they’re not part of the URL
  • Add restrictions for the top route for values of controller and/or action
  • Always use route links instead of action links, since they unambiguously state which route is the correct route.

Leave a Comment