ShaneKm
ShaneKm

Reputation: 21328

Using a dictionary to dynamically pass values to an ActionLink in ASP.NET MVC

Is there a way to pass a Dictionary<string, string> to Html.ActionLink()?

My Dictionary:

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

I tried doing this:

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

but that doesn't work

Upvotes: 0

Views: 1293

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038820

You could use the following overload:

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

where myDictionary should be an IDictionary<string, object>.

Upvotes: 3

Related Questions