Passing List<T> as query string
asp.net
Solution
I think you can do this. But if is a list comming from the database better call the function again on the revising page. Otherwise you have to do a dirty solution like this:
List<string> ls=new List<string>{"Sweden","USA"};
Response.Redirect("page.aspx?CountryList="+string.Join(",",ls));
And on the revising page do this:
List<string> ls= QueryString["CountryList"].Split(',').ToList();
But remember there is a limit on how large querystring you can send. So if the list contains many items then you can might reach that upper bound.
or store it in session:
Session["CountryList"]=ls;
And then on the revising page. Do this:
List<string> ls=(List<string>)Session["CountryList"];
Session.Remove("CountryList");
Remember to `remove` the `session` when you are done with it. So you do not have dirty values in the `session`
Problem
I have a List having country names in the list. And this list needs to be sent as one of the parameters in Response.Redirect(page). Is there a straight forward way to do this, so that in the recieving page, I can type cast the query string to List and use it. Thanks, Sriram