Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing TempData from HttpContext.Current

How can I access TempData from HttpContext.Current?

like image 285
BowserKingKoopa Avatar asked Mar 26 '11 19:03

BowserKingKoopa


People also ask

How do I view TempData?

we can easily show the tempdata message in view all we need to do is binding the message to tempdata. View Code : In view we need to check whether “Tempdata” is null or not , if it is not null then put in any html tags like p , span ,etc..

Is TempData stored in session?

It is stored in session storage, but there is one crucial difference between TempData and Session : TempData is available only for a user's session, so it persists only till we have read it and gets cleared at the end of an HTTP Request.

Can we access TempData in JavaScript?

TempData is created on Server Side of the Web application and hence it is not possible to directly set it on Client Side using JavaScript or jQuery. Thus, only possible way is to set it by making an AJAX call to the Controller's Action method using jQuery AJAX function in ASP.Net MVC Razor.


1 Answers

Addressing your comment to the other answer, you might implement your own ITempDataProvider and then override Controller to use it. Take a look at the CookieTempDataProvider class in Mvc3Futures which stores tempdata in cookies rather than session to see how this is possible.

http://volaresystems.com/Blog/post/2011/06/30/Sessionless-MVC-without-losing-TempData.aspx

Rather than changing where tempdata is stored, your implementation could possible inherit from SessionCookieTempDataProvider and simply add type-safe methods to it.

like image 159
Mike Avatar answered Oct 26 '22 09:10

Mike