Reputation: 1861
I have a simple view:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Administration
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Indexer stats</h2>
<div id="Stats">
<% Html.RenderPartial("IndexerStats", CmsModels.Utilities.BackgroundIndexer.Default); %>
</div>
</asp:Content>
How can I automatically refresh the Partial View "IndexStats" every 10 seconds?
I have found this code, but it doesn't compile with my version of MVC (2 RC).
Upvotes: 4
Views: 5962
Reputation: 1861
Damn it, you spend ages looking for an answer, ask the question and then find the answer imediately afterwards.
Revised code is:
<script src="<%=Url.Content("~/Scripts/jquery-1.3.2.min.js")%>" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
setInterval(function() {
$.get('<%=Url.Action("IndexerStats")%>', {}, function(view) {
$("div#IndexerStats").html(view);
})
}, 5000);
}); </script>
<div id="IndexerStats">
<% Html.RenderPartial("IndexerStats"); %>
</div>
</asp:Content>
However I am open to better ideas, or Html helpers.
Upvotes: 6