Question

In my MVC3 project I have a controller "Test" with this method for Index action

Function Index(fields() As String) As ViewResult
...

Then on the View I have a a multi-select drop down list

@Html.ListBox("fields", New MultiSelectList(my_list, "Value", "Text")) 

and everything works fine, however when I try to create an Actionlink passing multiple values of parameter "fields" in the querystring like this

@Html.ActionLink("TestLink", "Index", New With {
         .fields = "value1&fields=value2"}) 

I get the following broken link in the HTML source with the querystring encoded

<a href="/Test/Index?fields=value1%26fields%3Dvalue2">TestLink</a> 

How can I pass multiple values to a querystring parameter by ActionLink?

Was it helpful?

Solution

If you want to do this dynamically by fetching the values from the listbox simply put the listbox inside a form whose action is pointing the controller action you want to invoke and then use a submit button. HTML will then do the job for you.

If you want to generate an ActionLink you could use the following:

@Html.ActionLink(
    "TestLink", 
    "Index", 
    New RouteValueDictionary() From { 
        { "fields[0]", "value1" }, 
        { "fields[1]", "value2" } 
    }
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top