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
See Question&Answers more detail:
os