1

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?

2

2 Answers 2

2

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();
}
1
  • Thanks for your help. I applied the code above and was still having issues. I later found out that the controller action was defined as a Child Action only, which was stopping the call. Removing that made it work.
    – James Peel
    Sep 14, 2016 at 14:22
0

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.