The recommended approach for passing lists of values as a QueryString is
www.site.com/search?value=1&value=2&value=3&value=4
ASP.N
I've come up with a solution to this myself by making a new class RouteDataList()
public class RouteDataList : List
{
public RouteDataList(IEnumerable enumerable) : base(enumerable) { }
public RouteDataList() : base() { }
public override string ToString()
{
string output = "";
for (int i = 0; i < this.Count; i++)
{
output += i < this.Count - 1 ? this[i] + "-" : this[i].ToString();
}
return output;
}
public static List ParseInts(string input)
{
if (String.IsNullOrEmpty(input)) return null;
List parsedList = new List();
string[] split = input.Split('-');
foreach (string s in split)
{
int value;
if(Int32.TryParse(s, out value)) parsedList.Add(value);
}
return parsedList;
}
}
Use as follows:
RouteDataList valuelist = new RouteDataList(){5,6,7,8};
RouteDataList anothervaluelist = new RouteDataList(){12,13,14,15};
Then Pass to any function that takes a RouteValueDictionary/Anonymous Type:
return RedirectToAction("View", "Browse", new {valuelist, anothervaluelist } );
// Produces http://www.site.com/browse/view?valuelist=5-6-7-8&anothervaluelist=12-13-14-15
// To Parse back to a list:
List values = RouteDataList.ParseInts(HttpContext.Current.Request.QueryString["valuelist"])