---
title: "What is the use of Keep and Peek in “TempData”?"  
description: "What is the use of Keep and Peek in “TempData”?"  
author: "Anonymous User"  
published: 2019-10-15  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/33661/what-is-the-use-of-keep-and-peek-in-tempdata  
category: "asp.net mvc"  
tags: ["mvc"]  
reading_time: 2 minutes  

---

# What is the use of Keep and Peek in “TempData”?

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 the “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("Td").ToString();
```

If you want to read more in detail you can read from this detailed blog on MVC Peek and Keep.

## Answers

### Answer by Anonymous User

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 the “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("Td").ToString();
```

If you want to read more in detail you can read from this detailed blog on MVC Peek and Keep.


---

Original Source: https://www.mindstick.com/interview/33661/what-is-the-use-of-keep-and-peek-in-tempdata

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
