我有一个有趣的问题,TempData
对象没有将值传递给另一个 Controller 。
我将 Enroll Controller
的 HttpPost
方法中的 TempData["Enroll"]
设置为 Enroll
模型。然后,我在 Register Controller
的 HttpGet
方法中读取了 TempData["Enroll"]
对象,但是它是空的
/空
。
我需要跨 3 个 Controller 保存所有这些数据。
有什么想法吗?
这是一个代码片段
//EnrollController.cs
[HttpPost]
public ActionResult Index(EnrollModel model)
{
// ...
TempData["EnrollModel"] = model;
return RedirectToAction("Index", "Register");
}
// RegisterController.cs
public ActionResult Index(string type)
{
RegisterModel model = new RegisterModel();
EnrollModel enrollModel = TempData["EnrollModel"] as EnrollModel;
model.ClientType = enrollModel.ClientType;
// ...
}
最佳答案
我遇到了一个问题,在我的本地机器上重定向期间 TempData 丢失了。
我检查了 web.config sessionState 设置,它是 InProc,因此没问题。
原来我在 web.config 中得到了另一个设置,它是从生产系统中获取的。它看起来像这样:
<httpCookies requireSSL="true" />
将 requireSSL 设置为 false 后,TempData 工作正常。
关于c# - TempData 在 RedirectToAction 期间未结转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12256488/