单击后退按钮时存在MVC3 TempData

wog*_*les 8 c# asp.net-mvc

我正在使用TempData传递其他消息以显示请求中的通知:

    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();
    }
Run Code Online (Sandbox Code Playgroud)

索引视图:

<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>
Run Code Online (Sandbox Code Playgroud)

然后我在视图中显示错误通知,它工作得很好.我的问题出现之后,如果我点击另一个链接,然后按浏览器中的后退按钮,通知再次显示.

有没有办法阻止通知重新显示?

编辑:看起来像它,因为它缓存索引视图,因为当我点击后退按钮时,它没有在操作中遇到断点.

wog*_*les 15

通过阻止索引视图上的缓存来解决此问题:

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult Index()
Run Code Online (Sandbox Code Playgroud)