Both TempData[]
and static
fields can be used to pass data from ActionResult
to another.
Is there performance/memory difference? best practice?
I also noticed that when paging or sorting, the Detail function is recalled which lead that the list of cars should remain in memory.
public class TestController
{
private static IEnumerable<Cars> _cars;
public ActionResult Detials()
{
var uploadedCars = TempData["cars"] as IEnumerable<Cars>;
var testViewModel = new TestViewModel();
var result = TestViewModel.Process(uploadedCars);
//var result = TestViewModel.Process(_cars);
return View(result);
}
public ActionResult UploadCars(object obj)
{
// upload file ...
_cars= null; // reset value
//_cars= loader.GetAllCars(uploader);
TempData["cars"] = loader.GetAllCars(uploader);
return RedirectToAction("Detials");
}
}
}