how to use setstate and getstate correctly

Topics: Writing modules
Dec 15, 2012 at 4:12 PM
Edited Dec 15, 2012 at 4:13 PM

In my custom controller i have two actionmethods

 public ActionResult OpenSettings (string flowVersion, int flowID, FlowDisplayMode flowmode)
        {	   _workcontextaccessor.GetContext().SetState("ItemMetadata", MetadataItem);

 public ActionResult AddNewSetting(int elementtype)
		   var ItemElement = _workcontextaccessor.GetContext().GetState<MetadataItemType>("ItemMetadata").Setting1;




In one i am preserving the state of some custom object and in the other i am trying to get that object from state. 

Both of these methods are called through ajax calls.

I am still on orchard 1.5.1. 

But it seems that calling getstate from the second action does not bring back anything.

am  i using these methods correctly ? 

I guess my other alternative would be to store in session but would really like to know if am thinking correctly.



Dec 15, 2012 at 4:23 PM

The state that you store using SetState is only stored for the current HTTP request, so when you try to retrieve the value using another HTTP request, it won't be there.