0

I currently have a javascript code that should update my partial view every 3 seconds. But it doesn't work for some reason, the timer it self works.

   <script>
   setInterval(function () {
       var obj = document.getElementById("menubar");
       obj.innerHTML = "@Html.Partial("/Views/Menu.cshtml")";
   }, 3000);
   </script> 

This is my code, i am new to javascript. So i have no idea what's wrong. I tried to show my session as well, didn't work either.

Any help?

1
  • I've found out that it does work, but the session that is in the partial view doesn't get updated. I'm using ajax to stay on the same page, but this is causing asp.net mvc not to update session. Any solutions? Commented Mar 8, 2013 at 11:18

1 Answer 1

2

create an action like below.

public ActionResult Menu()
{
    return View();
}

better to keep your partial view in shared folder.

your javascript.

<script>
   setInterval(function () {
       $("#menubar").empty().load('/{controller_name}/Menu');
   }, 3000);
</script>

replace {controller_name} with the actual controller name.

Problem with your code was you are sticking the output of partial view into your javascript so everytime setIntervel was running it was picking the output from javascript not requesting it from your server.

Sign up to request clarification or add additional context in comments.

1 Comment

Assuming you are using jquery for ajax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.