4

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 Answers2

3

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
  • 8,207
  • 2
  • 34
  • 41
3

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

3Dave
  • 28,657
  • 18
  • 88
  • 151
Charlino
  • 15,802
  • 3
  • 58
  • 74
  • Yea!. The wrongly spelled stuff is because i wanted to translate the code a lil bit to english & make it more clear. The problem was indeed i turned around controller & action. Stupid mistake. Sorry for bothering you all with such a dumb question Tnx alot –  May 06 '10 at 09:11
  • 2
    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 May 06 '10 at 09:20