ChadT
ChadT

Reputation: 7713

ASP.NET MVC 3 RC Html.Actionlink not generating link

As the title says...

I have a route (the first one listed) which looks like this:

routes.MapRoute(
    "TopicRoute", // Route name
    "forums/{forumSlug}/{topicSlug}", // URL with parameters
    new { controller = "Forums", action = "Topic"} // Parameter defaults
);

I can browse to:

/forums/my-forum/my-topic

and the page loads fine. Yet I have a Html.ActionLink that looks like:

@Html.ActionLink(item.Title, "Topic", new { forumSlug ="my-forum", topicSlug = "my-topic" })

And it won't generate the correct link syntax for me? It generates:

<a href="">My Topic</a>

Upvotes: 0

Views: 3308

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039418

Don't forget the controller:

@Html.ActionLink(item.Title, "Topic", 
    new { forumSlug ="my-forum", topicSlug = "my-topic", controller = "Forums" })

or use a named route link:

@Html.RouteLink(item.Title, "TopicRoute", 
    new { forumSlug = "my-forum", topicSlug = "my-topic" })

Upvotes: 3

Related Questions