Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 );
}

or is there a better way using ajax stuff ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
789 views
Welcome To Ask or Share your Answers For Others

1 Answer

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); 
            }
        });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...