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

Ok, I am having some problems with the htmlhelper actionlink.

I have complicated routing:

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 to create action links matching these patterns. The eventname parameter is actually just for a convenient reference. he does not do anything.

Now when I try, for example, to create a link. which shows a dashboard of a certain level. How:

  mysite.com/testevent/20/Dashboard 

I will 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:

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

What I should have is something like:

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

Please carry me, I'm still new to ASP MVC. Can someone tell me what I am doing wrong?

Help will be appreciated!

+4
source share
2 answers

There are a few things here besides those that have already been mentioned - you also made a mistake in the Controller and Action lines.

This is the signature of the method, after which it looks like this:

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

So yours should be:

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

HTHS,
Charles

+3
source

I think the problem is that it cannot find a route matching these parameters. You have a GroupID with an error, and you entered a route parameter that does not exist ("EventName_Url") in the route that you are trying to map. The actionlink should probably look something like this:

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

Source: https://habr.com/ru/post/1308973/


All Articles