user323395
user323395

Reputation:

ASP.NET MVC: Html.Actionlink() generates empty link

Okay i'm experiencing some problems with the actionlink htmlhelper.

I have some complicated routing as follows:

        routes.MapRoute("Groep_Dashboard_Route", // Route name
                        "{EventName}/{GroupID}/Dashboard", // url with Paramters
                        new {controller = "Group", action="Dashboard"});

        routes.MapRoute("Event_Groep_Route", // Route name
                        "{EventName}/{GroupID}/{controller}/{action}/{id}",
                        new {controller = "Home", action = "Index"});

My problem is generating action links that match these patterns. The eventname parameter is really just for having a user friendly link. it doesn't do anything.

Now when i'm trying for example to generate a link. that shows the dashboard of a certain groep. Like:

  mysite.com/testevent/20/Dashboard

I'll use the following actionlink:

<%: Html.ActionLink("Show dashboard", "Group", "Dashboard",  new { EventName_Url = "test", GroepID = item.groepID}, null)%>

What my actual result in html gives is:

 <a href="">Show Dashboard</a>

What i should have is something like:

 <a href="test/20/Dashboard">Show Dashboard</a>

Please bear with me i'm still new at ASP MVC. Could someone tell me what i'm doing wrong?

Help would be appreciated!

Upvotes: 4

Views: 5224

Answers (2)

ten5peed
ten5peed

Reputation: 15890

There are a number of things wrong here, aside from what has already been pointed out - you've also got the Controller and Action strings around the wrong way.

This method signature you are after looks like this:

HtmlHelper.ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)

So your one needs to be:

<%: Html.ActionLink("Show dashboard", "Dashboard", "Group", new { EventName = "test", GroupID = item.groupID}, null) %>

HTHs,
Charles

Upvotes: 3

Mattias Jakobsson
Mattias Jakobsson

Reputation: 8237

I think the problem is that it doesn't find a route that match those parameters. You have misspelled GroupID and you have entered a route parameter that doesn't exist ("EventName_Url") in the route you are trying to match. The actionlink should probably look something like this:

<%: Html.ActionLink("Show dashboard", "Group", "Dashboard",  new { EventName = "test", GroupID = item.groepID}, null)%

Upvotes: 3

Related Questions