在应用程序状态 ASP.NET MVC 中保存项目列表?
我在了解如何保存 global.asax as- Application[""] 中处于应用程序状态的列表中的项目时遇到了一些麻烦。
我的控制器基本上接受一些用户输入,然后我将其传递给另一个类方法作为参数,它总是添加到列表中。这些数据被添加到我想要存储的列表中,但不使用数据库。通过使用应用程序状态。 。我一直在实例化此类并调用其方法来返回项目列表,但我不认为应用程序状态正在保存它。
这是我到目前为止所拥有的。 。
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;
}
^ 正在调用的类
SWTimeEnvInfoDTO 类型具有数据的 get 和 set 方法。
我也从视图调用应用程序。它适用于字符串
Application["AppID"] = "fgt";
当我从我的角度读到它时,就会显示这一点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:您应该使用转换来检索在应用程序中保存的变量,并在更改时保存它:
Updated: You should use casting to retrieve variable you have saved at Application, and save it if it has changed: