开发者

With MVC 2 I want to fire action every 10 seconds

I have a view called DataProgress and when it is shown in my browser, I want it to re-fire the same action that produced it every 10 seconds. My action is DataProgress in the controller MyController.

I tried the following, but it seems to fire the method ever few seconds (not 10 seco开发者_如何转开发nds) and in the browser I do not see anything shown at all.

<script>
  $(document).everyTime(10000, function () {
    <% Html.Action("DataProgress");%>;
  }, 100);
</script>

JD


<% Html.Action("DataProgress");%> does nothing but to render the action ONCE when the view is executed and to insert the result into the place where you placed the Action command.

In other words: Html.Action is a server-side command, it cannot be called by javascript code.

What you need to do is to use $.ajax() or similar jQuery methods (load and getJson might also work depending on your needs) and update your page accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜