MVC3 TempData exists when you click the back button

I use TempData to send additional messages to show notification of requests:

public ActionResult Address() TempData["NotificationType"] = "error"; TempData["NotificationMessage"] = "There was an error updating the address."; return RedirectToAction("Index", "Home"); } public ActionResult Index() { if (TempData["NotificationType"] != null && TempData["NotificationMessage"] != null) { model.NotificationMessage = TempData["NotificationMessage"].ToString(); model.NotificationType = TempData["NotificationType"].ToString(); } return View(); } 

Index Type:

 <div id="NotificationType" data-notification_type="@Model.NotificationType"/> <div id="NotificationMessage" data-notification_message="@Model.NotificationMessage" /> <script type=text/javascript> if($('#NotificationType').data('notification_type') == 'error'){ Notify('error', "Error!", $('#NotificationMessage').data('notification_message')); } </script> 

Then I show an error message in the view and it works fine. My problem arises after that, if I click another link, and then click the "Back" button in the browser, a notification will appear again.

Is there a way to prevent the notification from re-displaying?

EDIT: It looks like it is caching an index pointer, as it does not hit the breakpoint in action when I click the back button.

+6
source share
1 answer

This is fixed by preventing caching in the index view:

 [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] public ActionResult Index() 
+11
source

All Articles