ASP MVC RedirectToAction passing an array of objects without using ViewData
I have the following method
public ActionResult Search(FormCollection form)
{
开发者_如何学JAVA .......
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.
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...
精彩评论