2009-11-30 33 views
1

我知道,我可以使用下面的代码段刷新一个div:调用ASP.NET MVC控制器明确通过AJAX

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

但是这将创建一个链接;用户将不得不点击它来刷新视图。

我该如何使它自动化,即像是说如果我希望网格在每五秒钟后刷新一次?

回答

0

试试这个:

<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")); 
} 
相关问题