Interviewer And Interviewee Guide

MVC Developer Interview Question:

Explain me what is the use of Keep and Peek in “TempData”?

Submitted by: Muhammad
Once “TempData” is read in the current request it's not available in the subsequent request. If we want “TempData” to be read and also available in the subsequent request then after reading we need to call “Keep” method as shown in the code below.

@TempData["MyData"];
TempData.Keep("MyData");
The more shortcut way of achieving the same is by using “Peek”. This function helps to read as well advices MVC to maintain “TempData” for the subsequent request.

string str = TempData.Peek("MyData ").ToString();
Submitted by: Muhammad

Read Online MVC Developer Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.