InvalidOperationException: The 'Microsoft.AspNetCore.Mvc.ViewFeatures.Infrastructure.DefaultTempDataSerializer' cannot serialize an object of type 'System.Collections.Generic.List`1

Question: How do you solve: "InvalidOperationException: The 'Microsoft-AspNetCore-Mvc-ViewFeatures-Infrastructure-DefaultTempDataSerializer' cannot serialize an object of type 'System-Collections-Generic-List`1".


Please Login to see the rest of the answer

Answer: That is right, the Lists in C-Sharp objects therefore you should normalize or convert the List into the String and then Serialize the String. Then deserialize the serialized String (in this case the List) from the View or Controller. Keep in mind that TempData["MyKey"] = MyObject works the same too. You can't just throw an Object into a TempData, you need to do extra work converting that into a #Serializable Object like String or J#SON Object.

Let me know in the comments below if this makes sense. 


Write an Article
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.


© 2022 - ErnesTech - Privacy