ProgrammerGuide.Net | Step by Step Programmer Guide

What is the use of Keep and Peek in ASP.NET MVC TempData? | ASP.NET MVC Interview Question

IN ASP.NET MVC, Once TempData is read in the current request it will not be available in the subsequent requests. In order to make TempData in ASP.NET MVC to be read and also available in the subsequent request after reading, we need to call Keep method as shown in the code below.

@TempData[“MyData”];
TempData.Keep(“MyData”);

The same behavior can be achieved using Peek function in ASP.NET MVC. This function enables ASP.NET MVC to maintain TempData for the subsequent request.

string str = TempData.Peek(“MyData”).ToString();
Please click here for related products on Amazon!

Jayashee

Add comment

Want to Check Celebrities News?