Thad
Thad

Reputation: 1530

Mvc Action Link not using correct route

I have the following routes and typing them in the browser works fine and routes correctly, but if I use a Html.ActionLink, it tries using the DefaultStuff Route.

Routes

_routes.MapStuffRoute(
    "DefaultStuff",
    "stuff/{controller}/{id}",
    new { id = UrlParameter.Optional },
    new[] { typeof(BaseApiController).Namespace });

_routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new[] { typeof(BaseController).Namespace });

Page

@Html.ActionLink("Job Queues", "Index", "Job") // generates http://localhost/stuff/job?action=Index

What am I missing to allow ActionLink to generate http://localhost/stuff/index. Reversing the routes the ActionLink is correct but the Stuff does not work. Just a note, the StuffRoute sets the action name based on the information in the request.

Upvotes: 0

Views: 526

Answers (1)

Connor Ross
Connor Ross

Reputation: 355

It seems as though you actually are trying to map the controller "Job" to stuff. Currently your "DefaultStuff" route does not resolve an action, so it is putting it in as a query string value.

_routes.MapRoute(
"DefaultStuff",
"stuff/{action}/{id}",
new { controller="Job", id = UrlParameter.Optional },
new[] { typeof(BaseApiController).Namespace });

Upvotes: 1

Related Questions