I have a little issue with MVC application.
I have an action which save information in database like:
[HttpPost]
public ActionResult Save()
{
// do something to save
// save message in TempData
TempData["Message"] = "Message";
return RedirectToAction("Index");
}
I show an alert message which shows if an item was saved or not. I'm doing in two steps.
in Site.Master
<div id="message"><%=(TempData["Message"] as string)%></div>
in javascript
if($("#message").text().length)
{
alert $("#message").text();
}
After saving item, I will be redirected to Index
page and will display the alert box. That's fine.
The problem is the following: If I save item and redirected to Index
and after that I press backspace
key or click on Back
button of browser, the alert still is shown.
What have I to do to destroy TempData
value when going back using either backspace key or Back button of browser ? I don't want to display alert anymore in this case.
Thanks
try using ViewBag or ViewData.