MVC3 - 无法通过其他操作将int []传递给RedicrectToAction上的控制器操作

use*_*147 4 asp.net-mvc-3

我在同一个控制器中有2个动作.

public ActionResult Index(string filter, int[] checkedRecords)
Run Code Online (Sandbox Code Playgroud)

public ActionResult ExportChkedCSV(string filter, int[] checkedRecords)
Run Code Online (Sandbox Code Playgroud)

第二个Action(ExportChkedCSV)包含此重定向:

if (reject != 0)
        {
            return RedirectToAction("Index", new { filter, checkedRecords });
        }
Run Code Online (Sandbox Code Playgroud)

当我单步执行时,参数checkedRecords在RedirectToAction语句中正确填充,但是当它从那里命中Index ActionResult时,checkedRecords为null.我已经尝试过filter =,checkedRecords =等等.我从View到Controller都没有问题.如果我将数组类型更改为其他任何内容,我可以获取值 - 如何将int []从操作传递给action?我究竟做错了什么?谢谢

CD *_*ith 6

您不能在MVC中将复杂类型作为重定向参数发送,只能使用数字和字符串等原始类型

使用TempData传递数组

...
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
}
Run Code Online (Sandbox Code Playgroud)