How do I refresh a partial view every 3 seconds in MVC 4?

妖精的绣舞 提交于 2019-11-28 11:41:21

I think you need to make some changes to your ajax call. Here is an example of how I do the call

$.ajax({
    url: '@Url.Action("Action", "Controller")',
    type: 'post',
    cache: false,
    async: true,
    data: { id: "frmUser" },
    success: function(result){
        $('.divPartial').html(result);
    } 
});

on your controller I don't think you need the child action only. Also you are returning an empty partial view object. It should be

return partialView('_partialName', Model);

finally in your jquery to keep the call happening you need to retrigger the call. Try something like this

$(document).ready(function(){
    function RefreshPartial(){
        //this will wait 3 seconds and then fire the load partial function
        setTimeout(function(){
            loadPartialView();
            //recall this function so that it will continue to loop
            RefreshPartial();
        }, 3000);
    }
    //initialize the loop
    RefreshPartial();
}); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!