ASP.NET MVC 中的自动刷新 [英] Auto refresh in ASP.NET MVC

查看:38
本文介绍了ASP.NET MVC 中的自动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网络表单中我会这样做

In webforms I'd do

    <script type="text/JavaScript">
    function timedRefresh(timeoutPeriod) {
        setTimeout("location.reload(true);", timeoutPeriod);
    }
    </script>

    <body onload="JavaScript:timedRefresh(5000);">

或代码隐藏 Page_Load

or codebehind Page_Load

Response.AddHeader("Refresh", "5");

问题 如何在 ASP.NET MVC3 中让屏幕每 5 秒刷新一次

Question How to make the screen refresh every 5 seconds in ASP.NET MVC3

推荐答案

你可以在 MVC 中做同样的事情:

You could do the same in 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>

或在您的控制器操作中:

or in your controller action:

public ActionResult Index()
{
    Response.AddHeader("Refresh", "5");
    return View();
}

这篇关于ASP.NET MVC 中的自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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