How to automatically update MVC PartialView every second

I need to automatically update partialView on the page every second (or a given time interval)

I thought of the following method: this rite

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

or is there a better way to use ajax?

+4
source share
1 answer

The easiest way to do this is to have a Controller action that returns your partial view, and then simply enter get ajax in the setInterval function. Something like that:

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

All Articles