"UpdatePanel" in Razor (mvc 3) "UpdatePanel" in Razor (mvc 3) ajax ajax

"UpdatePanel" in Razor (mvc 3)


You can try something similar to the following using Jquery (have not tested though)

<script type="text/javascript">   $(document).ready(function() {        setInterval(function()        {         // not sure what the controller name is          $.post('<%= Url.Action("Refresh", "RefreshItems") %>', function(data) {           // Update the ItemList html element           $('#ItemList').html(data);          });        }        , 30000);   });</script>

The above code should be placed in the containing page i.e. not the partial view page. Bear in mind that the a partial view is not a complete html page.

My initial guess is that this script can be placed in the partial and modified as follows. Make sure that the ajax data type is set to html.

<script type="text/javascript">    setInterval(function()    {      // not sure what the controller name is      $.post('<%= Url.Action("Refresh", "RefreshItems") %>', function(data) {        // Update the ItemList html element        $('#ItemList').html(data);      });    }    , 30000);</script>

Another alternative is to store the javascript in a separate js file and use the Jquery getScript function in ajax success callback.


Well, if you don't need the AJAX expierience than use the HTML tag:

<meta http-equiv=”refresh” content=”30; URL=http://www.programmingfacts.com”>

go here: http://www.programmingfacts.com/auto-refresh-page-after-few-seconds-using-javascript/


If someone wants the complete code for a selfupdating partial view have a look!

Code of the Controller:

[HttpPost]public ActionResult RefreshSelfUpdatingPartial() {            // Setting the Models Content            // ...            return PartialView("_SelfUpdatingPartial", model);}

Code of the Partial (_SelfUpdatingPartial.cshtml):

@model YourModelClass<script type="text/javascript">setInterval(function () {    $.post('@Url.Action("RefreshSelfUpdatingPartial")', function (data) {            $('#SelfUpdatingPartialDiv').html(data);        }    );}, 20000);</script>// Div<div id="SelfUpdatingPartialDiv">// Link to Refresh per Click<p>@Ajax.ActionLink("Aktualisieren", "RefreshFlatschels", new AjaxOptions() {UpdateTargetId = "FlatschelList",HttpMethod = "Post", InsertionMode = InsertionMode.Replace})</p>// Your Code// ...</div>

Code to integrate the Partial in the "Main"-View (ViewWithSelfupdatingPartial.cs):

 @Html.Partial("_FlatschelOverview", Model)