Hold a data object temporarily in MVC controller,MVC,MVC Controller temp storage

user2866079 picture user2866079 · Oct 10, 2013 · Viewed 17.7k times · Source

I have a object that i want to store for a moment. The object is in a controller for now, the controller will generate a view. A AJAX request is made from the view to next controller. For that moment i need the object previously stored. Previously, i used session and it worked well. But not sure it is the right thing to do. Is session the answer for this or is there anything else?

I have used cache also.but as per the cache concept.It will access for all the users.So one user data will be override to another.So the cached object data will be change for the same user.I need to handle the data storage for an particular user(Independent).

How is it possible? anyother approach is there please share me.

In Controller I have used Httpcontext.cache["key"]=dataset;

but some one suggested like this.but its not displaying

Explain:

In Controller: httpcontext.current.cache is not coming.

HttpContext.Currenthandler and HttpContext.Currentnotification properties only coming.So How can we handle the temp data storage in MVC.

Please help me.

Answer

Alex picture Alex · Oct 10, 2013

You could use TempData if you want to store data for the next request only. If data should be accessible between multiple requests, then use Session. Here is short explanation of each one with examples.