繁体   English   中英

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

[英]ASP.NET MVC: Html.Actionlink() generates empty link

好吧,我遇到了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参数实际上只是用于友好的用户链接。 它没有做任何事情。

现在,当我试图生成链接时。 它显示了某个groep的仪表板。 喜欢:

  mysite.com/testevent/20/Dashboard

我将使用以下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_Url”)。 actionlink应该看起来像这样:

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

除了已经指出的内容之外,这里有很多错误 - 你还有错误的控制器和Action字符串。

您之后使用此方法签名如下所示:

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,
查尔斯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM