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
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
}
You are sending two null values. When you use new {} you are making a new object. You have to not only define the index names, but the values as well.
return RedirectToAction("Index", new { filter = filter, checkedRecords = checkedRecords });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With