0

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?

P.S. I need to access the data multiple time.

nebula
  • 3,932
  • 13
  • 53
  • 82
  • possible duplicate of [Passing useful message from one controller to redirected controller](http://stackoverflow.com/questions/6978253/passing-useful-message-from-one-controller-to-redirected-controller) – Eranga Jul 23 '12 at 09:50

1 Answers1

0

You can put your object to cache.

Add:

HttpContext.Current.Cache.Add("MyData", myObject, null, DateTime.Now.AddHours(6),
                        System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);

Retrive object:

var my object = HttpContext.Current.Cache["MyData"] as MyType
pauliusnrk
  • 593
  • 7
  • 18