ASP MVC RedirectToAction 传递对象数组而不使用 ViewData
我有以下方法
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您始终拥有 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...