1

I am writing an application wherein I need to send a System.Collections.ArrayList data as a parameter from one controller action to another. I am using

return RedirectToAction("action1","controller1", new { arrList = arrListInFirstAction});

But since the ArrayList goes out of scope in the first action, the parameter in the redirected to action receives a null parameter.

Can someone please help me find an answer to this problem.

Thanks.

1 Answer 1

3

you can not send complex types as route parameters. you can, however, use TempData collection to keep that object for one request and on next request it will be automatically removed from collection

publci ActionResutl action()
{
     TempData["arr"] = new int[]{1,2,3};
     return RedirectToAction("action1");
}

Public ActionResult action1()
{
    int[] arr = TempData["arr"];
    return View();
}
Sign up to request clarification or add additional context in comments.

2 Comments

@Amit That was easy, huh? =)
@Pete: Yup, it was pretty easy :)

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.