.Net

Tempdata.Keep() and Tempdata.Peek()

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 or “Peek ” method.

Keep() MethodPeek() Method
1.To read and retain the value with Keep one need to do two request, i.e. first read the value and in next statement call Keep method to retain value.With the help of Peek method one can do both operation in a single statement i.e. access as well retain value.
2.Keep provides 2 overload methods. One can save particular TempData on condition based and second can save all TempData’s value. There is no overloaded method in case of Peek method. Peek method always saves particular TempaData’s value.
3.RedirectResult and RedirectToRouteResult internally calls Keep method to retain items.Peek method is not called internally with any of ActionResult.
4.Once we retrieved value from object than it is marked for deletion, with Keep method we can later save object from Deletion. It means first deletion marking is happened then saving using Keep method.With Peek method we can retain TempData value without marking for deletion in a single call. It means deletion marking is not happening in case of Peek method. It directly persist TempData.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button