[英]ASP.NET MVC: Html.Actionlink() generates empty link
Okay i'm experiencing some problems with the actionlink htmlhelper. 好吧,我遇到了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.
eventname参数实际上只是用于友好的用户链接。 it doesn't do anything.
它没有做任何事情。
Now when i'm trying for example to generate a link. 现在,当我试图生成链接时。 that shows the dashboard of a certain groep.
它显示了某个groep的仪表板。 Like:
喜欢:
mysite.com/testevent/20/Dashboard
I'll use the following actionlink: 我将使用以下actionlink:
<%: Html.ActionLink("Show dashboard", "Group", "Dashboard", new { EventName_Url = "test", GroepID = item.groepID}, null)%>
What my actual result in html gives is: 我在html中给出的实际结果是:
<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. 请耐心等待我,我仍然是ASP MVC的新人。 Could someone tell me what i'm doing wrong?
有人能告诉我我做错了什么吗?
Help would be appreciated! 帮助将不胜感激!
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.
您有拼写错误的GroupID,并且您在尝试匹配的路线中输入了不存在的路线参数(“EventName_Url”)。 The actionlink should probably look something like this:
actionlink应该看起来像这样:
<%: Html.ActionLink("Show dashboard", "Group", "Dashboard", new { EventName = "test", GroupID = item.groepID}, null)%
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. 除了已经指出的内容之外,这里有很多错误 - 你还有错误的控制器和Action字符串。
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, HTHS,
Charles 查尔斯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.