6
存在时,我使用的TempData来传递更多的信息,显示通知翻过请求:MVC3 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();
}
索引视图:
<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>
我然后显示在错误通知视图和它的工作很好。 我之后遇到问题,如果我点击另一个链接,然后按浏览器中的后退按钮,通知再次显示。
有没有办法阻止重新显示通知?
编辑:看起来像它,因为它缓存索引视图,因为它没有击中后面的按钮时,在行动中的断点。
后搜索的小时终于找到了正确的解决方案。谢谢哥们。 –