c# - TempData 在 RedirectToAction 期间未结转

标签 c# .net asp.net-mvc-3 razor

我有一个有趣的问题,TempData 对象没有将值传递给另一个 Controller 。

我将 Enroll ControllerHttpPost 方法中的 TempData["Enroll"] 设置为 Enroll模型。然后,我在 Register ControllerHttpGet 方法中读取了 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/

相关文章:

C# - 根据类型将对象转换为 IList<T>

c# - 使多个矩形或区域无效

c# - 在哪里保存配置文件

c# - 在 native C++ 中编写 C# 托管代码

.net - 正则表达式不等于字符串

c# - ASP.NET MVC3和SQL DB:如何编写每天应调用一次的过程?

c# - 我想全选并复制到剪贴板

C# List AddRange - 它是否复制通过引用添加的项目

asp.net-mvc-3 - 使用示例数据为 Entity Framework 提供种子数据库不会创建数据库

asp.net-mvc-3 - ASP.NET Web API 问题 - 授权/身份验证