How to use TempData Keep() vs Peek() in ASP.NET MVC
By FoxLearn 2/18/2024 1:02:18 AM 279
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"];
- Unable to resolve service for type 'Microsoft.AspNetCore.Identity.RoleManager'
- ASP.NET MVC Responsive Templates Free Download
- How to upload file in ASP.NET MVC
- How to Create Contact Form Flat Responsive in ASP.NET MVC
- HTTP Error 500.30 ASP.NET Core app failed to start
- How to Use IExceptionHandler in ASP.NET Core
- How to custom exception handling in ASP.NET Core
- How to check if HttpPostedFileBase is an image
Categories
Popular Posts
Horizon MUI Admin Dashboard Template
11/18/2024
Plus Admin Dashboard Template
11/18/2024
Modular Admin Template
11/14/2024
Slim Material UI Admin Dashboard Template
11/15/2024
Freedash bootstrap lite
11/13/2024