Hi bigbear,
Since you are using PartialView you need use JavaScript setInterval function and make ajax call to refresh at specific interval.
Check below sample code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Controller
public class HomeController : Controller
{
// GET: Home
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Details()
{
NorthwindEntities entities = new NorthwindEntities();
return PartialView("Details", entities.Customers.OrderBy(x => Guid.NewGuid()).Take(10));
}
}
View
Index
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h4>Customers</h4>
<hr />
<div id="dvPartial"></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
setInterval(BindPartialView, 1000);
});
function BindPartialView() {
$.ajax({
type: "POST",
url: "/Home/Details",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function (response) {
$('#dvPartial').html(response);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
}
</script>
</body>
</html>
PartialView
@model IEnumerable<Partial_View_Core_MVC.Customer>
<table cellpadding="0" cellspacing="0" id="CustomerGrid">
<tr>
<th>CustomerID</th>
<th>Contact Name</th>
<th>City</th>
<th>Country</th>
</tr>
@foreach (Customer customer in Model)
{
<tr>
<td>@customer.CustomerID</td>
<td>@customer.ContactName</td>
<td>@customer.City</td>
<td>@customer.Country</td>
</tr>
}
</table>
Screenshot