Подтвердить что ты не робот

Автоматическое обновление в ASP.NET MVC

В веб-формах я бы сделал

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

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

или codebehind Page_Load

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

Вопрос Как обновить экран каждые 5 секунд в ASP.NET MVC3

4b9b3361

Ответ 1

Вы можете сделать то же самое в 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();
}