System.InvalidOperationException
TempData serializer 'Microsoft.AspNetCore.Mvc.ViewFeatures.Infrastructure.DefaultTempDataSerializer' cannot serialize property 'ChallengeHub.Web.Pages.Posts.CreateModel.AlertMessage' of type 'ChallengeHub.Web.ViewModel.AlertMessage'.
An unhandled exception occurred
Exception source not available.
Solution
TempData uses Sessions which uses strings, so you need to serialize your data using TempData["key"] = JsonConvert.SerializeObject(obj); and then deserialize it later using JsonConvert.DeserializeObject<DataType> https://stackoverflow.com/a/56529252/10548884
Sep 02, 2021
•
Anyone
Install the browser extension
Found this solution helpful? Try our extension for quick solutions to your .NET errors.
Add to Chrome - It's free
1 replies
hepalem
Thank you!