I have a form that use a control with the attribute multiple=”multitple”. This allow the user to select more than one item in the control.
When the form is submitted with the get method the url of the requested page contains one multiples parameters with the same name. One for each item selected. For exemple, I could get something like this :
/logs?levels=DEBUG&levels=INFO&levels=FATAL
In my controller the action correctly receive the values in a parameters of type List like this :
public ActionResult Index(List<String> levels)
{
...
}
Now, for some reason I need to create a link to this action that will include more than one values for the levels parameter. How can I use Html.ActionLink to create such a link? I tried it this way :
@Html.ActionLink((p + 1).ToString(), "Index", new {
levels = ViewBag.selectedLevels_AS_A_GENERIC_LIST_OF_STRINGS,
itemsPerPage = ViewBag.itemsPerPage
});
It does not work, because the list is not expanded in any way, instead .ToString() is called on it and the result is inserted into the link. Of course, there is no way for me to create an object with multiples properties named “levels” either.
How can I create an ActionLink like the one generated by the form I use?
Thanks
Something like this should work.