javascript 点击浏览器后退按钮时如何刷新 ASP .NET MVC 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21906971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:58:08  来源:igfitidea点击:

How to refresh ASP .NET MVC page when hitting browser back button

javascript.netbrowserasp.net-mvc-5page-refresh

提问by Developer

I just found that when I click browser back button on any ASP .NET MVC page nothing happens and page is not going be updated. And only if you click F5 it will be updated only.

我刚刚发现,当我在任何 ASP .NET MVC 页面上单击浏览器后退按钮时,什么也没有发生,页面也不会更新。并且仅当您单击 F5 时,它才会被更新。

The main problem that I do some changes of DOM of the page i.e. add table rows select radio-buttons and etc and when I go back to page by hitting browser back button I have see no changes.

主要问题是我对页面的 DOM 进行了一些更改,即添加表格行选择单选按钮等,当我通过点击浏览器后退按钮返回页面时,我没有看到任何变化。

How it can be resolved for ASP .NET MVC 5?

如何解决 ASP .NET MVC 5 的问题?

Thank for any clue...

感谢您提供任何线索...

P.S. I have read http://forums.asp.net/t/1304752.aspx?how+to+refresh+page+when+hitting+back+buttonbut it does not help...

PS 我已经阅读了http://forums.asp.net/t/1304752.aspx?how+to+refresh+page+when+hitting+back+button但它没有帮助......

回答by Developer

Here is a proper solution http://dotscrapbook.wordpress.com/2011/02/02/handling-a-browser-back-button-press-with-mvc/.

这是一个正确的解决方案http://dotscrapbook.wordpress.com/2011/02/02/handling-a-browser-back-button-press-with-mvc/

[HttpGet]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")] 
public ActionResult MyView()
{
  ...
}

回答by Jeyhun Rahimov

try this:

试试这个:

window.onbeforeunload = function() { location.reload(); };