Sunday, January 7, 2018

Difference Between Keep and Peek

Temp data persist the value for next request depending on following condition

1. Normal Read
2. Not Read
3. Read and Keep
4. Peek and Read


If you have read the data from TempData inside view or any other class than data will be deleted.

stringstr = TempData["MyData"];

Even if you are displaying the data it is also normal read
@TempData["MyData"];

2.If data not read than it will available until next next request.

3. If you read the data and called Keep method than data will be persisted.

@TempData["MyData"];
TempData.Keep("MyData");

4. You have read the data using Peek method than data will be read and persisted
stringstr = TempData.Peek("Td").ToString()


So the difference between keep and peek is keep force to persisted the data but not read the data. While
Peek read the data and persisted it for next request.

No comments:

Followers

Link