Cannot pass complex object to another Action method

I’m trying to pass an object using TempData to another action method. Instead of redirecting to the action method, the controller gives me a white screen with the current action method in the URL. If I comment out the line where I pass the object to TempData, it redirects correctly. Is my object too complex to pass? Is there an alternative way of passing a complex object to another action methods?

Where I pass the object to TempData:

public async Task<IActionResult> UploadFile(IFormFile file)
{
    if (file == null || file.Length == 0)
        return Content("file not selected");
    else
    {                
        var path = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot",
                "processes.json");

        using (var stream = new FileStream(path, FileMode.Create))
        {
            await file.CopyToAsync(stream);

        }
        RetrieveModels rm = rm = new RetrieveModels(path);
        List<FoundPattern> foundList = new List<FoundPattern>();               
        List<ProcessModel> processes = rm.Processes;
        FindPatterns findp = new FindPatterns(processes, pt.KpiPatterns);
        foundList = findp.fp;
        TempData["list"] = foundList.ToList();
        TempData["Name"] = "Multiple Business Processes";
        return RedirectToAction("Overview");
    }           
}

Action method I want to get redirected to:

public IActionResult Overview()
{
    var list = TempData["list"] as List<FoundPattern>;
    ViewData["Name"] = TempData["Name"];
    return View(list);
}

List of objects I’m trying to pass to TempData:

public class FoundPattern
{
    public KpiPattern pattern = new KpiPattern();
    public List<FoundElement> elements = new List<FoundElement>();
}

List of objects within object:

public class FoundElement
{
    public List<string> ElementNames = new List<string>();
    public bool Present { get; set; }
}

Response headers when it works:

HTTP/1.1 302 Found
Location: /Home/Overview
Server: Kestrel
Set-Cookie: .AspNetCore.Mvc.CookieTempDataProvider=CfDJ8Mu_qDgU_59HncGqqkEm39LG_cUi_rzUyuXXaEYreUFPL2etHRuHPv_5GVKDLcIIcvFhQg1KOzDBfhbvDbjZDpcp8JYzq5kpLHtfnw962pyXNHyCNbx_MOkKwGFSG_dQ_M7LlSVxWYHjqalsSe26K4IlRfGN8V9B5MAgIhWoURgF; path=/; samesite=strict; httponly
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcWkFUXHNvdXJjZVxyZXBvc1xLUEl0b29sXEtQSXRvb2xcSG9tZVxVcGxvYWRGaWxl?=
X-Powered-By: ASP.NET
Date: Wed, 07 Feb 2018 10:38:40 GMT
Content-Length: 0

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Server: Kestrel
Set-Cookie: .AspNetCore.Mvc.CookieTempDataProvider=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; samesite=strict
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcWkFUXHNvdXJjZVxyZXBvc1xLUEl0b29sXEtQSXRvb2xcSG9tZVxPdmVydmlldw==?=
X-Powered-By: ASP.NET
Date: Wed, 07 Feb 2018 10:38:40 GMT

Response headers when it doesn’t work:

HTTP/1.1 500 Internal Server Error
Server: Kestrel
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcWkFUXHNvdXJjZVxyZXBvc1xLUEl0b29sXEtQSXRvb2xcSG9tZVxVcGxvYWRGaWxl?=
X-Powered-By: ASP.NET
Date: Wed, 07 Feb 2018 10:41:28 GMT
Content-Length: 0

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You are using the CookieTempDataProvider to manage TempData. Alas, it results in storing the TempData in cookies, as the name suggests.

The problem is that your data is too large to fit in the cookie. You may wish to use a different ITempDataProvider implementation (such as SessionStateTempDataProvider).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x