I'm implementing an ASP.NET MVC post/redirect/getpattern in an Azure website. When a user creates a new entity they are redirected from the create view to the edit view with the new object id as part of the url.
The entity has quite a few fields so it's not uncommon to save multiple times and to reassure the user that their data is being saved we are showing a 'Saved successfully' message using javascript.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Branch branch, int orgs)
{
if (ModelState.IsValid)
{
// model is valid, save it and redirect to edit
_branchRepository.Save(branch);
TempData["Message"] = new NotificationViewModel(NotificationSeverity.Success,
"Saved",
"Saved successfully");
return RedirectToAction("Edit", new { id = branch.Id });
}
// model is invalid, don't save it, let them have another go
TempData["Message"] = new NotificationViewModel(NotificationSeverity.Warning,
"I'm sorry, Dave.",
"I'm afraid I can't do that.");
ModelState.Clear();
return View("Edit", branch);
}
My understanding of TempData is that any data stored in TempData will be around for the life the current request and the next request only (or until the item is removed explicitly) and is the best place to put data you want to pass another view that you will be redirecting to.
Is TempData the best place for this message?
Note: I've read that if you're load balancing your webservers that you have to have Sticky Sessions enabled. Does Azure turn on Sticky Sessions automatically or do you need to manually configure this?