2

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?

2
  • 1
    Are you against using TempData? Commented Nov 4, 2010 at 21:53
  • Yea...I cant really use TempData in my case..I am passing this url to .swf which uses it... Commented Nov 4, 2010 at 21:54

1 Answer 1

2

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)));
}
Sign up to request clarification or add additional context in comments.

1 Comment

a slight problem i have is I am trying to pass two lists...and somehow it does not do it right when i am doing it...it passes the same list in the both the lists (the second one)...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.