I’m currently migrating an existing ASP.NET MVC application to ASP.NET Core. To share data between multiple page requests I’m trying to use the TempData. TempData stores your data until it's read in another request.
This is how my code looked like:
Unfortunately this resulted in a 500 error without any further explanation 😒.
What am I doing wrong? The thing is that you cannot store a complex object inside the TempData directly. Instead of returning a meaningful error you get only a 500 message.
To fix it, I added some serialization logic before storing the object in the TempData dictionary:
This is how my code looked like:
Unfortunately this resulted in a 500 error without any further explanation 😒.
What am I doing wrong? The thing is that you cannot store a complex object inside the TempData directly. Instead of returning a meaningful error you get only a 500 message.
To fix it, I added some serialization logic before storing the object in the TempData dictionary: