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".

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. 

© 2023 - ErnesTech - Privacy