传递的ArrayList参数控制器动作ASP.NET MVC [英] Passing ArrayList parameter to controller action ASP.NET MVC

查看:125
本文介绍了传递的ArrayList参数控制器动作ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个应用程序,其中我需要从一个控制器动作发送System.Collections.ArrayList数据作为参数传递给另一个。
我使用

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});

但由于该ArrayList超出范围在第一时间行动,在重定向到动作参数接收一个空参数。

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.

感谢。

推荐答案

您不能发送复杂类型的路由参数。你可以,但是,使用TempData集合,以保持该对象的一个​​请求,并在接下来的请求时,它会从集合被自动删除

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();
}

这篇关于传递的ArrayList参数控制器动作ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆