我哈瓦2个控制器:ControllerA和ControllerB,以及在controllerA会议设定值,但在ControllerB不能获得价值,这样的代码:C#MVC会话是空
public class ControllerA : Controller
{
public ActionResult Index()
{
Session["a"] = "test";
}
}
public class ControllerB : Controller
{
public ActionResult Index()
{
ViewBag.Test = Session["a"].ToString();
}
}
我试图使用cookie来代替的会话,但有同样的问题。 我不知道我是否应该在C#MVC中使用会话,请让我知道是否有更好的会话。谢谢。
http://stackoverflow.com/questions/560084/session-variables-in-asp-net-mvc – Simon 2014-10-22 11:09:16
可以显示真实的代码,而不是样品 – 2014-10-22 11:10:04
已经在这里回答了多个建议的解决方案: http://stackoverflow.com/questions/10629882/asp-net-mvc-session-is-null – Rimmon 2014-10-22 11:13:22