gpt4 book ai didi

c# - 单击后退按钮时存在 MVC3 TempData

转载 作者:太空狗 更新时间:2023-10-29 18:16:29 25 4
gpt4 key购买 nike

我正在使用 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();
}

索引 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>

然后我在 View 中显示错误通知,效果很好。如果我单击另一个链接然后按浏览器中的后退按钮,我的问题就会再次显示。

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

编辑: 看起来是这样,因为它缓存了索引 View ,因为当我按下后退按钮时它没有在操作中遇到断点。

最佳答案

通过阻止在索引 View 上缓存来修复此问题:

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

关于c# - 单击后退按钮时存在 MVC3 TempData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13949341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com