I've been using TempData for a long time and faced strange issue for me. I have basic scenario:
[HttpPost]
public ActionResult Create(ProductCreateModel newProduct)
{
// create and save product to db
// try upload product to external site
try { UploadProductToEbay(newProduct); }
catch {
TempData["error"] = "error";
return RedirectToAction("Edit", newProduct.Id);
}
...
}
[HttpGet]
public ActionResult Edit(int Id)
{
var error = TempData["error"]; // at this point temp data collection is empty and have no idea why
...
}
The issue takes place when upload fails and return RedirectToAction("Edit", newProduct.Id);
line is executed. What could be not very obvious reasons of losing temp data values?
UPDATE: When I use
TempData["error"] = "error";
RedirectToAction(...);
outside the catch
block everything works fine, temp data value is transfered to Edit
action.