C# ASP.NET MVC:Html.Actionlink()生成空链接

C# ASP.NET MVC:Html.Actionlink()生成空链接,c#,asp.net,asp.net-mvc,routing,asp.net-routing,C#,Asp.net,Asp.net Mvc,Routing,Asp.net Routing,好的,我在actionlink htmlhelper上遇到了一些问题 我有一些复杂的路线如下: routes.MapRoute("Groep_Dashboard_Route", // Route name "{EventName}/{GroupID}/Dashboard", // url with Paramters new {controller = "Group", action=

好的,我在actionlink htmlhelper上遇到了一些问题

我有一些复杂的路线如下:

        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"});
我的问题是生成与这些模式匹配的操作链接。 eventname参数实际上只是为了拥有一个用户友好的链接。它没有任何作用

例如,当我尝试生成一个链接时。这显示了某个集团的仪表盘。 比如:

我将使用以下actionlink:

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

我在html中的实际结果是:

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

我应该做的是:

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

请容忍我,我还是ASP MVC的新手。有人能告诉我我做错了什么吗


谢谢你的帮助

我认为问题在于它找不到与这些参数匹配的路由。您拼错了GroupID,并且输入了一个在您试图匹配的路由中不存在的路由参数(“EventName\u Url”)。actionlink的外观可能如下所示:

<%: Html.ActionLink("Show dashboard", "Group", "Dashboard",  new { EventName = "test", GroupID = item.groepID}, null)%
HtmlHelper.ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)

除了已经指出的之外,这里还有很多错误之处——控制器和动作字符串的使用方法也有错误

您要查找的此方法签名如下所示:

<%: Html.ActionLink("Show dashboard", "Group", "Dashboard",  new { EventName = "test", GroupID = item.groepID}, null)%
HtmlHelper.ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
所以你的人需要:

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

HTHs,

查尔斯

是的!。拼写错误的东西是因为我想把代码稍微翻译成英语&让它更清楚。问题确实是我把控制器和动作转过来了。愚蠢的错误。很抱歉用这样一个愚蠢的问题来打扰你们大家Tnx alotMate,不要对自己太苛刻。。。我们都有自己的pebkac时刻!无论问题看起来多么简单或难,都要不断地发帖:-)Ps.pebkac=[p]问题存在于[k]黑板[a]和[c]头发之间