在返回点击刷新页面 - MVC 4 [英] Refresh Page on Back Click - MVC 4

查看:109
本文介绍了在返回点击刷新页面 - MVC 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一个简单的办法,迫使我的的ActionResult 来一直火的时候,我打这个页面?在浏览器后退一下,例如,这将不会执行。我不想总是有当不需要刷新页面,但我不知道如何有条件地做到这一点。

 公众的ActionResult指数()
{
    //做一些事情总是    返回查看();
}


解决方案

的ActionResult 禁用缓存将强制页面每次刷新,而不是渲染缓存的版本。

  [OutputCacheAttribute(的VaryByParam =*,持续时间= 0,NoStore = TRUE)]
公众的ActionResult指数()
{
    //做一些事情总是    返回查看();
}

现在,当您点击浏览器后退按钮时,这个被击中每次。

What would be a simple way to force my ActionResult to always fire when I hit this page? On browser back click, for instance, this will not execute. I don't want to always have to refresh the page when not necessary, but I'm not sure how to do this conditionally.

public ActionResult Index()
{
    //do something always

    return View();
}

解决方案

Disabling cache on the ActionResult forces the page to refresh each time rather than rendering the cached version.

[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)]
public ActionResult Index()
{
    //do something always

    return View();
}

Now when you click the browsers back button, this is hit every time.

这篇关于在返回点击刷新页面 - MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆