ASP MVC RedirectToAction 传递对象数组而不使用 ViewData

发布于 2024-10-31 16:41:53 字数 1276 浏览 1 评论 0原文

我有以下方法

 public ActionResult Search(FormCollection form)
    {
         .......
        Publication[] publicationsResult = server.SearchLibrary(this.getSession(), sq);

        return RedirectToAction("BookListing", new { publications = publicationsResult });
    }

,它从服务器获取出版物列表并将其存储在出版物类型的数组中。

我想在另一个页面中显示结果,因此我重定向到以下方法:

public ActionResult BookListing(Publication[] publications)
    {
        Publication[] p = publications;
        return View(publications);
    }

并且我还定义了以下路由:

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Library", action = "Search", id = UrlParameter.Optional } // Parameter defaults
        );

        routes.MapRoute(
            "PublicationListing", // Route name
            "{controller}/{action}/{publications}", // URL with parameters
            new { controller = "Library", action = "BookListing", publications = UrlParameter.Optional } // Parameter defaults
        );

搜索中时,出版物数组填充了超过 13000 个对象,但是当我重定向到 BookListing null 被传递。

有没有一种方法可以使用 RedirectToAction 将对象数组从一个操作方法传递到另一个操作方法?

谢谢。

I have the following method

 public ActionResult Search(FormCollection form)
    {
         .......
        Publication[] publicationsResult = server.SearchLibrary(this.getSession(), sq);

        return RedirectToAction("BookListing", new { publications = publicationsResult });
    }

Which gets a list of publications from the server and stores it in an array of type Publication.

I would like to show the results in another page, thus I redirected to the following method:

public ActionResult BookListing(Publication[] publications)
    {
        Publication[] p = publications;
        return View(publications);
    }

And I also have the following Routes defined:

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Library", action = "Search", id = UrlParameter.Optional } // Parameter defaults
        );

        routes.MapRoute(
            "PublicationListing", // Route name
            "{controller}/{action}/{publications}", // URL with parameters
            new { controller = "Library", action = "BookListing", publications = UrlParameter.Optional } // Parameter defaults
        );

When in Search the publications array is populated with over 13000 objects, however when I redirect to BookListing null is passed.

Is there a way to pass an array of objects from one action method to another using RedirectToAction?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-11-07 16:41:53

您始终拥有 TempData 集合。这是在单个请求的操作重定向之间持续存在的,因此为您提供了类似这样的存储空间......

You always have the TempData collection. This is persisted between the action redirects for a single request and so provides you with storage for anything like this...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文