0
return RedirectToAction("ActionName", new { lst = finalData });
[HttpGet]
 Public ActionResult AcionName(IGrouping<string, ModelName> lst)
 {
  return View("ActionName", lst);
 }

i use this code to redirect my list to another action but this is not working.

  • Welcome to SO! Can we have a minimal, complete and verifiable example of your code? https://stackoverflow.com/help/mcve –  Oct 11 '17 at 08:22
  • 1
    You cannot pass complex objects like that using `RedirectToAction()`. Save the data, then pass just its ID to the GET method and get it again in the GET method –  Oct 11 '17 at 10:05

1 Answers1

0

You can assign the finalData to a Session or TempData variable.

TempData["FinalData "] = finalData;
return RedirectToAction("ActionName");

From this answer: "TempData Allows you to store data that will survive for a redirect. Internally it uses the Session, it's just that after the redirect is made the data is automatically evicted"

Then in your GET Action Method,

Public ActionResult AcionName()
{
    var finalData = TempData["FinalData"] as IGrouping<string, ModelName>;
    return View("ActionName", finalData);
}

The problem is, if you were to refresh after the redirect, then finalData would be null. So, in that case you use Session["FinalData"] or get the data from the Database in your Get method again. You can go through the answer I have linked for disadvantages of using TempData.

adiga
  • 34,372
  • 9
  • 61
  • 83