What is Keep and Peek Method with TempData in MVC [Resolved]

Posted by Kumarkrishna184 under ASP.NET MVC on 4/3/2016 | Points: 10 | Views : 660 | Status : [Member] | Replies : 2
What is Keep and Peek Method with TempData in MVC

Thanks and Regards,
Krishna Kumar



Responses

Posted by: Sheonarayan on: 4/3/2016 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
Good question Kumar...

Peek is the combination of Retrieval and Keep method, let's try to understand this with an example.

Keep - Look at following code snippet, we have called the Keep method just after reading the TempData. In this case, Keep method instruct the MVC that retain the value of TempData for next request
 string data = TempData["MyTempData"].ToString();
TempData.Keep("MyTempData"); // above like is mandatory

Peek - In case we want to retrieve data from TempData and retain them for next request, we can directly use Peek instead of above code snippet.

So Peek is the combination of retrieval and Keep method (above code snippet)

 string data = TempData.Peek("MyTempData").ToString();

You can read the complete tutorials at http://techfunda.com/howto/236/pass-data-from-one-action-method-to-another that is also written by me.

Hope this helps.
Thanks



Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarkrishna184 on: 4/5/2016 [Member] Starter | Points: 25

Up
0
Down
Thank Sheonarayan Sir....

Thanks and Regards,
Krishna Kumar

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response