Passing a List values with a GET in asp.net mvc?
I have the following data-
IList<int> mylist= new List<int>();
int value=0;
ViewData["URL"] = "/Services/Getdata/?value="+&value+"&mylist="+mylist;
// It hits this function
public void Getdata(int value,IList<int> mylist)
{}
Now the problem is the list is not being passed over correctly...I am doing a GET here and cannot post the data...so now I know it has to some how pass it like &mylist[0]=2&mylist[1]=3..so on
...So how can achieve this...I found this but are there other alternatives?
Please help me out here..I can't really开发者_运维百科 use TempData in my case..all I want is to pass an list or array through wire in asp.net mvc? Has anyone done something like this before?
You could use the following function to serialize your list to one string:
public string Serialize(System.Collections.Generic.IList<int> list, string paramName) {
return String.Join("&", list.Select((value, index) => String.Format(CultureInfo.InvariantCulture, "{0}[{1}]={2}", paramName, index, value)));
}
精彩评论