Not able to redirect to action when using TempData in Asp.Net Core

此生再无相见时 提交于 2019-12-03 16:24:50

@Win. You were right. I realized the serialization, deserialization is required whenever you want to use TempData in Asp.net Core after reading the disclaimer in this article.

https://andrewlock.net/post-redirect-get-using-tempdata-in-asp-net-core/

I first tried to use BinaryFormatter but discovered that it has also been removed from .NET Core. Then I used NewtonSoft.Json to serialize and deserialize.

TempData["CustomerDetails"] = JsonConvert.SerializeObject(customer);

public IActionResult Registered()
    {
        Customer customer = JsonConvert.DeserializeObject<Customer>(TempData["CustomerDetails"].ToString());
        return View(customer);
    }

That's the extra work we have to do now but looks like that's how it is now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!