定期刷新局部视图(ASP.Net MVC)

Mr.*_*Zen 7 asp.net asp.net-mvc

我需要定期刷新.Net的局部视图.它正在使用Ajax.ActionLink,是否有类似的定期刷新功能?我可以不使用jQuery吗?

Fel*_*ani 12

禅,你可以用这样的代码来做:

function loadPartialView() {
   $.ajax({
    url: "@Url.Action("ActionName", "ControllerName")",
    type: 'GET', // <-- make a async request by GET
    dataType: 'html', // <-- to expect an html response
    success: function(result) {
                $('#YourDiv').html(result);
             }
   });
}

$(function() {

   loadPartialView(); // first time

   // re-call the function each 5 seconds
   window.setInterval("loadPartialView()", 5000);

});
Run Code Online (Sandbox Code Playgroud)

记住你的Action应该返回一个PartialView.我希望它对你有所帮助!