I have a post action Import:
public ActionResult Import()
{
var fileNames = new List<String>();
foreach (string path in Directory.GetFiles(directoryPath))
{
//do a whole bunch of stuff
...
fileNames.Add(path.Split('\\').Last());
}
return RedirectToAction("Index", new { InvalidFiles = fileNames });
}
As you can see, it redirects to an Index action, passing the List<String> of file names
public ActionResult Index(List<String> InvalidFiles)
{
return View();
}
In the Index action, the List comes in with the right amount of elements, however all the actual strings has been changed from the filename to the string “System.Collections.Generic.List`1[System.String]”.
Any idea why this is happening? Is there a better way to pass the list to the new action, possibly using TempData?
You can use TempData to temporally hold the data between actions.