views:

103

answers:

1

I know that I can use following piece of code to refresh a div:

<%=Ajax.ActionLink( "Update", "Administration", new AjaxOptions { UpdateTargetId = "grid", LoadingElementId = "grid-wait" } ) %>

But this creates a link; user will have to click on it to get the view refreshed.

How can I make it automatic, i.e., like say if I want the grid to be refreshed after every five seconds?

A: 

Try this:

<p id="CurrentDateTime"></p>

<script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

<script type="text/javascript">
    window.setInterval(updateDateTime, 5000);
    function updateDateTime() {
        $.get("GetCurrentDate?rnd=" + Math.random(1000), {}, function (r) {
            $("#CurrentDateTime").html(r);
        }, "text");
    }
</script>

public ActionResult GetCurrentDate()
{
    return Content(DateTime.Now.ToString("U"));
}
Mehdi Golchin