Javascript ASP.NET MVC 中的自动刷新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5396282/
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-08-23 17:00:37 来源:igfitidea点击:
Auto refresh in ASP.NET MVC
提问by Dave Mateer
In webforms I'd do
在网络表单中我会做
<script type="text/JavaScript">
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);", timeoutPeriod);
}
</script>
<body onload="JavaScript:timedRefresh(5000);">
or codebehind Page_Load
或代码隐藏 Page_Load
Response.AddHeader("Refresh", "5");
QuestionHow to make the screen refresh every 5 seconds in ASP.NET MVC3
问题如何在 ASP.NET MVC3 中让屏幕每 5 秒刷新一次
回答by Darin Dimitrov
You could do the same in MVC:
你可以在 MVC 中做同样的事情:
<script type="text/javascript">
function timedRefresh(timeoutPeriod) {
setTimeout(function() {
location.reload(true);
}, timeoutPeriod);
}
</script>
<body onload="JavaScript:timedRefresh(5000);">
...
</body>
or using a meta tag:
或使用元标记:
<head>
<title></title>
<meta http-equiv="refresh" content="5" />
</head>
<body>
...
</body>
or in your controller action:
或在您的控制器操作中:
public ActionResult Index()
{
Response.AddHeader("Refresh", "5");
return View();
}