How can I access TempData from HttpContext.Current?
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..
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With