Reputation: 179
I have a partial view that I am loading in using:
<div class="row">
<div class="col-xs-12">
@Html.Action("NewFaults", "Fault")
</div>
</div>
This ultimately loads a partial view called _NewFaults.cshtml
and I want to refresh every 10 seconds (for example) to regularly show any new faults that come in. I have been looking around online for how to do this for a while, but all the examples I find are very specific to their example and it's not obvious how to adapt them.
Can someone help me?
Upvotes: 1
Views: 6141
Reputation: 1427
Use setInterval()
function.
function myFunction() {
setInterval(function(){ window.location.href='redirectURL.php' }, 10000); //Referesh particular page
//OR
setInterval(function(){ window.location.reload() }, 10000); //Referesh curent page
}
http://www.w3schools.com/jsref/met_win_setinterval.asp
Upvotes: 0
Reputation: 475
As per the comment, use a javascript timer
var timer = setInterval(YourFunction, 10000);
where YourFunction does an AJAX call to your controller for a partial view.
$.ajax({
url: "@Url.Action("Action","Controller")",
type: 'POST',
dataType: 'html',
cache: false,
success: function (html) {
//show it on page
}
});
to such a method
public PartialView Action()
{
return PartialView();
}
Upvotes: 2