I have a simple Partial View that I would like to automatically call a method on the server every 5 second.
Load the Partial View from the Master Layout:
@{Html.RenderAction("PingServer", "Account"); }
The Controller looks like this:
public ActionResult PingServer()
{
return PartialView("PingServer");
}
The actual “_PingServer” Partial View is:
@{
<script language="javascript" type="text/javascript"
src="http://code.jquery.com/jquery-latest.js">
</script>
<script language="javascript" type="text/javascript">
$(function () {
setInterval(Foo, 5000);
});
function Foo() {
$.post("/Shared/ImHere.ashx", null, function () { });
}
</script>
}
The Actual "ImHere.ashx.cs" looks like this:
public class ImHere : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
SiteUser.ImHere();
}
public bool IsReusable
{
get
{
return false;
}
}
}
======================
THIS IS JUST NOT WORKING.
It actually used to work on MVC2 but NO MORE on MVC3.
I understand the way Partial Views are handle in MVC3 is now a bit different with that concept of “_” (underscore) and not sure if that is the problem.
I tried renaming that partial view _PingServer …but still NO effect.
Maybe it’s that I load the Partial View as Html.RenderAction instead of Html.RenderPartial ?
The idea is that that call needs to run every 5 seconds and not change a single thing on the page.
Any thoughts??
You don’t need to use
RenderAction, you can just useto render the partial view. Using this eliminates the need for the
PingServer()action method.Also your partial view shouldn’t be within
@ { }justas it is just HTML