R – How to repeat the same ASP.NET MVC action again

actionlinkasp.net-mvcnetrouting

I have an action called List that shows the results of a search. It receives parameters through the querystring because they are optional. My method signature looks like this:

public ActionResult List(List<int> categoryIDs, string school, int? stateID, int? page)

CategoryIDs is a multi-select box and I am doing everything over a GET request. What I need to do is create a link in my view to the next page but retain the same search parameters. I know I can build the link by hand but it is possible to use any of the built-in routing method especially when the categoryIDs have to be formatted like "?categoryID=1&categoryID=2&categoryID=3" to be bound to the list?

Best Answer

I think there's no ActionLink overload that helps you do that by default. You need to populate the RouteValueDictionary instance with the parameters you want to include.

For the list of category, try s/t like categoryIDs=2,3,4,5 etc. since repeating keys are not allowed in RouteValueDictionary. After that, in the action method will need to parse the string into the integer list.