How to use TempData Keep() vs Peek() in ASP.NET MVC
By FoxLearn 2/18/2024 1:02:18 AM 116
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"];
- How to fix Font Awesome WebFont woff2 not working BundleConfig
- How to Minify HTML using WebMarkupMin in ASP.NET Core
- How to Minify HTML using WebMarkupMin in ASP.NET MVC
- How to Minify HTML output from ASP.NET MVC
- How to fix 'IMvcBuilder' does not contain a definition for 'AddNewtonsoftJson'
- How to fix System.InvalidOperationException: Scheme already exists: Identity.Application
- The name 'Session' does not exist in the current context
- How to fix 'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer'
Categories
Popular Posts
C# Tutorial
07/20/2024
How to Download Microsoft SQL Server
06/22/2024
What Are RESTful Web Services?
02/19/2024