Skip to main content

Posts

Showing posts from July, 2019

TempData keep() vs peek()

When an object in a  TempDataDictionary  is read, it will be marked for deletion at the end of that request. That means if you put something on TempData like TempData [ "value" ] = "someValueForNextRequest" ; And on another request you access it, the value will be there but as soon as you read it, the value will be marked for deletion: //second request, read value and is marked for deletion object value = TempData [ "value" ]; //third request, value is not there as it was deleted at the end of the second request TempData [ "value" ] == null The  Peek  and  Keep  methods allow you to read the value without marking it for deletion. Say we get back to the first request where the value was saved to TempData. With  Peek  you get the value without marking it for deletion with a single call, see  msdn : //second request, PEEK value so it is not deleted at the end of the request object value = TempData . Peek ( "value"