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>
我然後顯示在錯誤通知視圖和它的工作很好。 我之後遇到問題,如果我點擊另一個鏈接,然後按瀏覽器中的後退按鈕,通知再次顯示。
有沒有辦法阻止重新顯示通知?
編輯:看起來像它,因爲它緩存索引視圖,因爲它沒有擊中後面的按鈕時,在行動中的斷點。
後搜索的小時終於找到了正確的解決方案。謝謝哥們。 –