Question: How do you solve this error in Asp.Net 6? "The 'Microsoft.AspNetCore.Mvc.ViewFeature.Infrastructure.DefaultTempDataSerializer' cannot serialize an object of type 'System.Decimal'"
I tried to pass data from one View to the ViewComponent by storing the decimal in the TempData["MyValueName"] = 34.00M; It worked fine but then it threw an error.
Login to See the Rest of the Answer
Answer: Remember the TempData can only store data when it hasn't been accessed, once another Component Accesses the data in the TempData the data gets deleted. Make sure that the Value you are storing in the TempData is actually available before an attempt to store it.
Like the error says, the TempData works well with the Data Type of Strings, convert the decimal to string by appending
TempData["MyValueName"] = "34.00" or = MyCurrentValue.ToString();
I hope this helps, if it did please leave a comment below indicating how you solved the issue. No login is required to leave a comment.