我知道如何从global.asax as- Application [“”]中的应用程序状态列表中保存项目时遇到了一些麻烦。
我的控制器基本上接受了一些用户输入,然后我将它传递给另一个类Method作为参数,它一直被添加到列表中。这些数据将被添加到我想要存储的列表中,但不使用数据库。使用Application State。 。我一直在实例化这个类并调用它的方法来返回项目列表,但我不认为Application State正在保存它。
这是我到目前为止所拥有的。
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
SWTimeEnvInfoDTO类型具有数据的get和set方法。
我也是从View调用应用程序。它适用于字符串
申请[“AppID”] =“fgt”;
并在我从我的观点中阅读后显示此内容。
答案 0 :(得分:1)
已更新:您应该使用强制转换来检索已在应用程序中保存的变量,并在已更改时保存它:
IList<SWTimeEnvInfoDTO> result = Application["AppID"] != null ? (IList<SWTimeEnvInfoDTO>)Application["AppID"] : new List<SWTimeEnvInfoDTO>(); // retrieve data
result.Add(...); // add some new items
Application["AppID"] = result; // save added values