MVC3 - Having trouble passing int[] to controller action on RedicrectToAction from a different action

asp.net-mvc-3

Solution

You can't send complex types as redirect parameters in MVC, only primitive types like numerics and strings

Use TempData to pass the array

...
if (reject != 0) {
    TempData["CheckedRecords"] = yourArray;
    return RedirectToAction("Index", new { filter = filterValue });
}
...

public ActionResult Index(string filter) {
    int[] newArrayVariable;
    if(TempData["CheckedRecords"] != null) {
        newArrayVariable = (int[])TempData["CheckedRecords"];
    }
    //rest of your code here
}

Problem

I have 2 actions within the same controller. ``` public ActionResult Index(string filter, int[] checkedRecords) ``` and ``` public ActionResult ExportChkedCSV(string filter, int[] checkedRecords) ``` The second Action (ExportChkedCSV) contains this redirect: ``` if (reject != 0) { return RedirectToAction("Index", new { filter, checkedRecords }); } ``` When I step through, the parameter checkedRecords is populated correctly on the RedirectToAction statement, but when it hits the Index ActionResult from there, checkedRecords is null. I've tried doing filter =, checkedRecords =, etc. I am having no problem with this from View to Controller. If I change the array type to anything else, I can grab the value - how do I pass int[] from action to action? What am I doing wrong? Thank you

Original source