views:

203

answers:

2

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!

+2  A: 

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)%
Mattias Jakobsson
+2  A: 

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.ActionLinke("Show dashboard", "Dashboard", "Group", new { EventName = "test", GroupID = item.groupID}, null) %>

HTHs,
Charles

Charlino
wh0emPah
Mate, don't be so hard on yourself... we all have our fair share of pebkac moments! Keep posting questions no matter how easy or hard they seem to be :-) Ps. pebkac = [p]roblem [e]xists [b]etween [k]eyboard [a]nd [c]hair
Charlino