簡體   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