Datetime TempData error in C# .NET Core 6 and razor page
Remi
0
Reputation points
TempData["abc"] = "2023-12-12" ;
TempData["abc_raw"] = "2023-12-12 10:10:00 PM";
return RedirectToPage();
The two are the same, but there is a problem with TempData["abc"].
"abc" cause
System.InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.String'.
Datetime to string cast error
So I temporarily used "abc" by serializing
TempData["abc"] = JsonSerializer.Serialize(TempData["abc"]);
Developer technologies ASP.NET ASP.NET Core
4,815 questions
Developer technologies .NET Other
4,103 questions
Sign in to answer