使用字典将值动态传递给ASP.NET MVC中的ActionLink

时间:2011-01-26 16:54:49

标签: asp.net-mvc asp.net-mvc-2

有没有办法将Dictionary<string, string>传递给Html.ActionLink()

我的词典:

var myDictionary = new Dictionary<string, string> { { "serviceId", "2342" } }

我试过这样做:

Html.ActionLink("Text here", "Action","Controller", myDictionary, null)

但这不起作用

1 个答案:

答案 0 :(得分:3)

您可以使用以下overload

<%= Html.ActionLink(
    "Text here", 
    "Action", 
    "Controller", 
    new RouteValueDictionary(myDictionary), 
    null
) %>

其中myDictionary应为IDictionary<string, object>