我正在尝试访问自定义类中的会话变量,如下所示:
控制器:
public void RemoveMachinesListChanged(object sender, RemovePackageEvent e)
{
PackageActionStatus.Current.Machines = e.Machines;
// Dictionary<int, int> machines = e.Machines;
}
public class PackageActionStatus
{
public static PackageActionStatus Current
{
get
{
HttpContextWrapper context = new HttpContextWrapper(System.Web.HttpContext.Current);
var session = (PackageActionStatus)context.Session["PackageActionStatus"];
if (session == null)
{
session = new PackageActionStatus();
context.Session["PackageActionStatus"] = session;
}
return session;
}
}
private Dictionary<int, int> machines;
public Dictionary<int, int> Machines
{
get
{
return this.machines;
}
set
{
if (this.machines == null)
{
this.machines = new Dictionary<int, int>();
}
this.machines = value;
}
}
}
我在这里想要实现的是通过 AJAX 调用从/向会话变量存储和检索值。似乎每当我使用ajax HttpContext 时都是空的。我该怎么做?谢谢