The code snippet below might indicate that you do not understand how TempData and the Keep() method work in ASP.NET Core as the code is redundant.
TempData["pid"] = 1003;
TempData.Keep("pid")
TempData is kept for one read. Once read, TempData is marked for deletion and not available on subsequent requests. Use Peek(string) to fetch an indexed item from TempData without marking the item for deletion.
I assume you read the "pid" value somewhere along the way when you should have used Peek().
var temp = TempData.Peek("pid");
Another way to do the same is...
int id = Convert.ToInt32(TempData["pid"]);
TempData.Keep("pid");
All-Star
52961 Points
23565 Posts
Re: TempData
Nov 20, 2019 07:38 PM|mgebhard|LINK
The code snippet below might indicate that you do not understand how TempData and the Keep() method work in ASP.NET Core as the code is redundant.
TempData is kept for one read. Once read, TempData is marked for deletion and not available on subsequent requests. Use Peek(string) to fetch an indexed item from TempData without marking the item for deletion.
I assume you read the "pid" value somewhere along the way when you should have used Peek().
Another way to do the same is...
See the following.
https://www.learnrazorpages.com/razor-pages/tempdata