【发布时间】:2021-02-16 11:57:06
【问题描述】:
在 Asp.net MVC 中:第一次重定向的 TempData 为空,在第二次重定向中有效,有时效果很好,有时获得第三次重定向
需要多次刷新页面才能看到TempData的效果
它在本地主机上运行良好,但在服务器上无法正常运行。
例如:
在下面这段代码中的“VerifyPaymentView”动作tempdata[“VerifyInfo”]第一次为null,需要多次刷新页面才能得到tempdata的内容
public async Task<ActionResult> Verify(int id)
{
var verifyInfo = await VerifyPayment(id, new List<Func<HttpRequestBase, Presenter, PayData, Task<VerifyCallbackData>>>()
{
SetPackage,
SetExam,
SetQuestionBankId,
SetQuestionBankGroupId,
SetReportCardLink,
VerifySpace
});
if (verifyInfo == null)
{
TempData["Error"] = true;
return RedirectToAction("VerifyPaymentView");
}
TempData["VerifyInfo"] = verifyInfo;
return RedirectToAction("VerifyPaymentView");
}
public ActionResult VerifyPaymentView()
{
var userId = User.GetUserId();
var isLogin = User.Identity.IsAuthenticated;
if (TempData["Error"] != null)
{
TempData["Error"] = true;
return View();
}
if (TempData["VerifyInfo"] != null)
{
var verifyInfo = (VerifyInfo)TempData["VerifyInfo"];
return View(verifyInfo);
}
return null;
}
【问题讨论】:
标签: asp.net-mvc tempdata