Question

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.

  1. in Site.Master

    <div id="message"><%=(TempData["Message"] as string)%></div>
    
  2. 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

Was it helpful?

Solution

try using ViewBag or ViewData.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top