Is there something like UpdatePanel (in ASPX) for Razor?
I want to refresh data (e.g. table, chart, ...) automaticly every 30 seconds. Similar to clicking the following link every 30 seconds:
@Ajax.ActionLink("Refresh", "RefreshItems", new AjaxOptions() {
UpdateTargetId = "ItemList",
HttpMethod = "Post"})
Edit:
I may should add that the action link renders a partial view.
Code in cshtml:
<div id="ItemList">
@Html.Partial("_ItemList", Model)
</div>
Code in Controller:
[HttpPost]
public ActionResult RefreshItems() {
try {
// Fill List/Model
...
// Return Partial
return PartialView("_ItemList", model);
}
catch (Exception ex) {
return RedirectToAction("Index");
}
}
It would be create if the PartielView could refresh itself.
You can try something similar to the following using Jquery (have not tested though)
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
.Another alternative is to store the javascript in a separate
js
file and use the Jquery getScript function in ajax success callback.The
<meta refresh ..>
tag in HTML will work for you. Its the best optionWell, if you don't need the AJAX expierience than use the HTML tag:
go here: http://www.programmingfacts.com/auto-refresh-page-after-few-seconds-using-javascript/
Traditional controls don't works in ASP MVC
You could do it using Jquery timers http://plugins.jquery.com/project/timers
Other option could be to use the Delay function
In your target is as simple as refresh the whole page, this SO link will be of your interest: Auto refresh in ASP.NET MVC
Hope It Helps.
If someone wants the complete code for a selfupdating partial view have a look!
Code of the Controller:
Code of the Partial (_SelfUpdatingPartial.cshtml):
Code to integrate the Partial in the "Main"-View (ViewWithSelfupdatingPartial.cs):