使用TempData字典会阻止RedirectToAction正常工作 [英] Using TempData dictionary prevents RedirectToAction from working

查看:73
本文介绍了使用TempData字典会阻止RedirectToAction正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将视图模型添加到TempData以便将其传递给这样的另一个控制器(请参考最后两行):

I want to add view model to TempData in order to pass it to another controller like this (referring to last 2 lines):

[HttpPost("register")]
public async Task<IActionResult> Register(RegisterViewModel rvm)
{
    if (ModelState.IsValid)
    {
        var result = await _authManager.RegisterUserAsync(rvm.FullName, rvm.Email, rvm.Password);

        if (result.IsSuccessful)
        {
            return RedirectToAction("Login", "Home", new { message = result.Message });
        }
        else
        {
            TempData["rvm"] = rvm;
            return RedirectToAction("Register", "Home");
        }
    }

    TempData["rvm"] = rvm;
    return RedirectToAction("Register", "Home");
}

问题在于,执行此操作后,RedirectToAction方法实际上不起作用,并且留下空白页(URL也不变).我补充说,没有TempData行,一切正常.

The problem is that, after performing this operation, the RedirectToAction method doesn't actually work and I'm being left with a blank page (the url also doesn't change). I add that, without the TempData line, everything works fine.

有人建议我在这里错了吗?

Any suggestions what am I dong wrong here?

首页/注册

[HttpGet("register")]
public IActionResult Register()
{
    RegisterViewModel rvm = (RegisterViewModel)TempData["rvm"];
    return View(rvm);
}

推荐答案

答案不多,但是我遇到了同样的问题,没有解决方法.我将tempdata更改为Session ["rvm"]变量,并成功.考虑从tempdata转为Session.

It is not much of an answer, but I experienced the same issue with no resolution. I changed tempdata to a Session["rvm"] variable and was successful. Consider pivoting from tempdata to Session.

这篇关于使用TempData字典会阻止RedirectToAction正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆