gpt4 book ai didi

asp.net-mvc-3 - 在 session 中存储对象

转载 作者:行者123 更新时间:2023-12-04 09:41:33 24 4
gpt4 key购买 nike

我知道这个主题已经在很多帖子中讨论过了,但是我无法解决。

在ActionResult内部的 Controller 内我想在Session中存储一个对象,然后在另一个ActionResult中检索它。像那样 :

    public ActionResult Step1()
{
return View();
}

[HttpPost]
public ActionResult Step1(Step1VM step1)
{
if (ModelState.IsValid)
{
WizardProductVM wiz = new WizardProductVM();
wiz.Step1 = step1;
//Store the wizard in session
// .....
return View("Step2");
}
return View(step1);
}

[HttpPost]
public ActionResult Step2(Step2VM step2)
{
if (ModelState.IsValid)
{
//Pull the wizard from the session
// .....
wiz.Step2 = step2;
//Store the wizard in session again
// .....
return View("Step3");
}
}

最佳答案

存储向导:

Session["object"] = wiz;

获取向导:
WizardProductVM wiz = (WizardProductVM)Session["object"];

关于asp.net-mvc-3 - 在 session 中存储对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11885451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com