如何自动刷新MVC PartialView每一秒 [英] how to auto refresh MVC PartialView every second

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

问题描述

我需要自动刷新页面每秒钟一个partialView(或设定的时间间隔)

i need to auto refresh a partialView in the page every second (or a set interval of time)

我想下面的方法之一是这个仪式

i thought of the following method is this rite

  loop 
{
     setInterval(function() {  <%Html.RenderPartial("partialview", Model);%> } ,1000 );
}

或者是有用ajax的东西更好的办法?

or is there a better way using ajax stuff ?

推荐答案

要做到这一点是有一个控制器动作,返回你的局部视图然后在setInterval函数只是做一个Ajax GET请求的最简单方法。事情是这样的:

The easiest way to do this would be to have a Controller action which returns your partial view then in the setInterval function just make an ajax get request. Something like this:

  $.ajax({
            url: '/MyController/PartialViewAction',
            type: "GET",
            success: function(result) {
               $("#partialContainer").html(result); 
            }
        });

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

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