Here is another way to do this:
- use AJAX and
setTimeout - declare one action in your controller (this will return your different values)
- an integer in your
ViewBag , some like: ViewBag.totalItems
Declare an action in the controller: This is important because it will be your connection to your database or data. This action will receive itemIndex and return this item. Something like that:
[HttpPost] public JsonResult GetItem(int index) { return Json(myList.ElementAt(index)); }
ViewBag.TotalItems . Your opinion should know how many items you have on the list. I recommend passing this value as an integer through the ViewBag :
public ActionResult Index() { ViewBag.TotalItems = myList.Count(); return View(); }
AJAX and setTimeout . After that, you have it all, you are ready to update your view without updating:
<script> $(function() { var totalItems = @Html.Raw(Json.Encode(ViewBag.TotalItems)); var currentItemIndex = 0; var getData = function() { $.post("@Url.Action("GetItem")", {index:currentItemIndex}, function(data) { </script>
source share