Saving a list of items in Application State ASP.NET MVC?

Saving a list of items in Application State ASP.NET MVC?

I'm having a bit of trouble with knowing how I can save items from a list I have in Application state in the global.asax as- Application[""].

My controller basically takes in some user input, I then pass this to another classes Method as parameters it gets added to a list all the time. This data thats getting added to the list I want to store it, but without using a db. By using Application State. . I have been instantiating this class and calling its method to return the list of items but I dont think Application State is saving it.

Here is what I have so far. .

        protected void Application_Start()     {         RegisterRoutes(RouteTable.Routes);           TimeLineInformation t = new TimeLineInformation();         IList<SWTimeEnvInfoDTO> g = t.getInfo();          Application["AppID"] =  g;     } 

^ Global.asax

        IList<SWTimeEnvInfoDTO> result = new List<SWTimeEnvInfoDTO>();      public  void returnTimeLineInfo(string SWrelease, string EnvName, DateTime SDate, DateTime EDate) {           SWTimeEnvInfoDTO myDTO = new SWTimeEnvInfoDTO();         myDTO.softwareReleaseName = SWrelease;         myDTO.environmentName = EnvName;          myDTO.StartDate = SDate;         myDTO.EndDate = EDate;          result.Add(myDTO);          getInfo();       }       public IList<SWTimeEnvInfoDTO> getInfo() {          return result;      } 

^ class im calling

The SWTimeEnvInfoDTO type has get and set methods for the data.

I am calling the application from a View as well. It works with a string

Application["AppID"] = "fgt";

and shows this once i read it from my view.

RedirectToAction help: or better suggestion


How would you show which tab is selected on a website built from a template?
Updated: You should use casting to retrieve variable you have saved at Application, and save it if it has changed:. mvc ajax.actionlink with jquery dialog confirm
IList<SWTimeEnvInfoDTO> result = Application["AppID"] != null ? (IList<SWTimeEnvInfoDTO>)Application["AppID"] : new List<SWTimeEnvInfoDTO>(); // retrieve data    result.Add(...);               // add any  new items Application["AppID"] = result; // save added values mvc return data from codebehind of aspx page

97 out of 100 based on 72 user ratings 507 reviews