Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Storing objects (non-string things) in TempDataDictionary does not round trip correctly #2276

@pranavkm

Description

@pranavkm

Scenario

public class FeedbackController : Controller
{
    private const string _userKey = "user-data";

    [HttpPost]
    public IActionResult SubmitApplication(string name, int age)
    {
        // Do db stuff
        var user = new User { Id = 100, Name = name, Age = age };
        TempData[_userKey] = user;
        return RedirectToAction("WelcomeUser");
    }

    public string WelcomeUser()
    {
        var user = (User)TempData[_userKey];
        return "Welcome " + user.Name;
    }
}

Expected (per behavior in Mvc 5)
Ouputs Hello {userName}

Actual
Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'User'.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions