How to use TempData Keep() vs Peek() in ASP.NET MVC
By FoxLearn Published on Feb 18, 2024 549
Your object in a TempDataDictionary is read, it will be marked for deletion at the end of that request
That means if you put something on TempData like
TempData["category"] = "your value";
first request
object value = TempData["catetory"];
second request
object value = TempData["category"]; //value = null
If you want to keep value you can use Keep method.
object value = TempData["category"]; //keep it to use later TempData.Keep("value"); //second request, read value and mark it for deletion object value = TempData["category"];
If you want to retain the value for another request, you can use Peek. Use Keep when retaining the value depends on additional logic.
//It will be not deleted at the end of the request object value = TempData.Peek("category"); //second request, read value and mark it for deletion object value = TempData["category"];
- Essential Tips for Securing Your ASP.NET Website
- Top Security Best Practices for ASP.NET
- Boost Your ASP.NET Core Website Performance with .NET Profiler
- The name 'Session' does not exist in the current context
- Implementing Two-Factor Authentication with Google Authenticator in ASP.NET Core
- How to securely reverse-proxy ASP.NET Core
- How to Retrieve Client IP in ASP.NET Core Behind a Reverse Proxy
- Only one parameter per action may be bound from body in ASP.NET Core
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
Dec 19, 2024
AdminKit Bootstrap 5 HTML5 UI Kits Template
Nov 17, 2024
RuangAdmin Template
Nov 13, 2024
Admin BSB Free Bootstrap Admin Dashboard
Nov 14, 2024