0

I'am trying to using Tempdata[] to store some objects on redirect and it's not working.

I tried in controller that returns RedirectToAction("Index"):

TempData["something"] = objectarray;

where objectarray is an array of objects.

and then obj[] foundmoviesfromredirect = (obj[])TempData["something"]; in an controller that returns View(list);

There is some problem with serializing that object as I get the error:

An unhandled exception has occurred: The 'Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.TempDataSerializer' cannot serialize an object of type <the type>

What I'am looking to do is to store objects in the object array, and pass that array to another controller adding the contents to a list in that controller and return the view. I'am having some really hard time to pass this object array to the another controller.

In short, is it impossible to use tempdata to store an object between requests? If not, how is it possible?

Arnar Freyr
  • 353
  • 1
  • 2
  • 12
  • TempData is the correct bag for storing objects between requests, but it only allows a limited set of types for serialization. The above linked question shows how to handle this by first serializing the object to JSON for storage. – Jonathon Chase Mar 21 '18 at 00:47
  • Wow, I viewed this link above like 1000 times when googling...and now first I'am getting it after like 3 days of ,,banging the head in the wall" situation :( Yes, This post is duplicate, but I did not need to make a whole new class. Like in the link. I think it's nice to point that out just in case if you just have a small project. The comment from @JonathonChase was enough for me to understand that it just enough to serialize and then deserialize instead of making a whole new class. – Arnar Freyr Mar 21 '18 at 01:25

0 Answers0