【问题标题】:how to auto refresh MVC PartialView every second如何每秒自动刷新 MVC 局部视图
【发布时间】:2010-12-03 06:51:49
【问题描述】:

我需要每秒(或设定的时间间隔)自动刷新页面中的部分视图

我想到了下面的方法就是这个仪式

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

或者有没有更好的使用 ajax 的方法?

【问题讨论】:

  • 你能发表你的部分观点吗?

标签: asp.net-mvc jquery partial-views


【解决方案1】:

执行此操作的最简单方法是使用 Controller 操作返回您的局部视图,然后在 setInterval 函数中发出 ajax get 请求。像这样:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    相关资源
    最近更新 更多