在webforms中我会做
<script type="text/JavaScript">
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);", timeoutPeriod);
}
</script>
<body onload="JavaScript:timedRefresh(5000);">
或代码隐藏Page_Load
Response.AddHeader("Refresh", "5");
问题如何在ASP.NET MVC3中每5秒刷新一次屏幕
答案 0 :(得分:75)
你可以在MVC中做同样的事情:
<script type="text/javascript">
function timedRefresh(timeoutPeriod) {
setTimeout(function() {
location.reload(true);
}, timeoutPeriod);
}
</script>
<body onload="JavaScript:timedRefresh(5000);">
...
</body>
或使用元标记:
<head>
<title></title>
<meta http-equiv="refresh" content="5" />
</head>
<body>
...
</body>
或在您的控制器操作中:
public ActionResult Index()
{
Response.AddHeader("Refresh", "5");
return View();
}