0

I have some code which show popup when submit button clicked

$(document).ready(function() {
  ....
  @if (TempData.ContainsKey("TripUpdateSuccess"))
    {
        @:alertify.set({ delay: 3000 });
        @:alertify.success("Transport " + @(Model.BookingID) + " has been updated.");
        TempData.Remove("TripUpdateSuccess");
    }
}

When user clicked save, submit occurs and this popup shows (alertify.js) Then user hits back button, and this popup shows again. Seems back button restores state of TempData object in ASP.NET MVC.

My task is not to show this popup when back button pressed. How this can be done ?

Forgot to say, submit redirects to this page, so this is why back button points to this page.

[HttpPost]
public ActionResult TripUpdate(TripUpdateModel model)
{
   ....
   // pseudo code
   if (ok)
      TempData["TripUpdateSuccess"] = true;
   else if (TempData.ContainsKey("TripUpdateSuccess"))
                    TempData.Remove("TripUpdateSuccess");

}
user3328720
  • 85
  • 1
  • 3
  • 11

2 Answers2

0

What's the problem? Do you need to hide popup when user hits back button?

user3127896
  • 6,323
  • 15
  • 39
  • 65
0

Based on your comment:

"Not sure how its going, but action method not called when back button clicked"

It sounds like you are getting a cached version of the page when you click the back button instead of it actually doing a full round trip to the database. Essentially you need to disable the page from being cached by the browser so you get a full round trip.

Take a look at this thread: Back button not requesting asp.net mvc get method

Community
  • 1
  • 1
Nick Olsen
  • 6,299
  • 11
  • 53
  • 75