0

In Home Created Index as on View and PartialView as ViewData

But Div is not getting refresh.

<script type="text/javascript">

   $(document).ready(function () {

       var refreshid = setInterval(function () {
           alert("test");
           $("#dynamictabs").load("/Home/Index/")
       }, 9000);
       $.ajaxSetup({ cache: false });
   });

</script>
<div class="dynamictabs">
   @Html.Partial("ViewData", @Model);
</div>
Cœur
  • 37,241
  • 25
  • 195
  • 267
user1493249
  • 11
  • 1
  • 5

2 Answers2

1

Try the following:

<script type="text/javascript">
    $(document).ready(function () {
        window.setInterval(function () {
            var url = '@Url.Action("SomePartial", "Home")';
            $('#dynamictabs').load(url)
        }, 9000);
        $.ajaxSetup({ cache: false });
    });
</script>
<div class="dynamictabs">
    @Html.Partial("SomePartial")
</div>

and then you will have a controller:

public class HomeController: Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult SomePartial()
    {
        return PartialView();
    }
}

and then you will have a SomePartial.cshtml:

@DateTime.Now
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

Could you explain more on what you are trying to do here, please? Based on your code I see you have set your interval to 9 seconds. And you are trying to load content from home/index into #dynamictabs. Is this element on the same page?

antoniovassell
  • 1,012
  • 14
  • 24
  • yes, It is in the same page. actually im very new to MVC3. Can you provide me with some help regarding user controls in MVC3. atleast Sample code will be helpful. Thank you.. – user1493249 Jun 30 '12 at 20:32
  • Sorry, not .net fan. but I hope this previous question and answers can help you though -> http://stackoverflow.com/questions/4811732/usercontrol-equivalent-in-mvc3. If its jQuery/Javascript I would be happy to help. – antoniovassell Jul 01 '12 at 01:23