i am using TempData to store the referrer f开发者_Go百科or a website and via jquery i am issueing ajax calls to send emails ... I use tempdata to recover the original referrer URL.
It works great on the first read but then the second its empty.... I think this is by design... so i decided to try viewdata but this is stored but when read via the controller on an ajax call it is empty..
Does anyone know what my options are?
Here is the syntax of both lines
TempData["referrer"] = referrer; // WORKS great on first read and then is NULL
ViewData["referrer"] = referrer; // IS STORED but on first read is NULL
Any help really appreciated
TempData persists only for the next request, as you've seen - it's really there for when you're performing something like a redirect and want to be sure that the next call has the data it needs. See this link for good detail:
TempData is really RedirectData
Note that link suggests that you may need to check both ViewData and TempData for a key.
Instead of these two facilities you could consider using Session
to store data for the entire user session, or consider stashing your information in the query string or a hidden form field.
Session["referrer"] = referrer;
精彩评论