JS back button clicked

2014-03-12 javascript asp.net-mvc

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.");

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.

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



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

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