使用jQuery调用控制器动作 [英] Using jQuery To Call A Controller Action

查看:102
本文介绍了使用jQuery调用控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个漂亮的网页,做我需要的一切。然而元素(部分页面)之一需要几秒钟时间较长的话,我想载入。因此,我想要做的是显示的页面没有这部分的第一,但表现在它的地方正在加载GIF。然后在我的jQuery ...

I have a nice page that does everything I need. However one of the elements (a partial page) takes a few seconds longer then I'd like to load. So what I'd like to do is to show the page without this partial first but show a "loading" gif in its place. Then in my jquery...

$(document).ready(function() {

   // Call controller/action (i.e. Client/GetStuff)

});

我想请我的控制器动作,返回一个PartialView并更新我的分区的内容。它基本上呼吁偏载异步的负载。我能做到这一点蛮好用的ActionLink的,直到它得到的的地方,我想onload事件做了点。如果我使用jQuery的onloand呼叫类型,可我甚至返回PartialView?

I'd like to call my controller action that returns a PartialView and updates my div contents. It basically calls the partial load asynchronously on load. I could do this just fine with an ActionLink until it get's to the point where I'd like to do it onload. If I use jQuery for the onloand type call, can I even return a PartialView?

推荐答案

只需使用 $ .load

$(document).ready(function() {    
   $('#myDiv').html('<img src="loading.gif"/>')
              .load('Client/GetStuff');   
});

这将与您的负载指示器替换股利的id =myDiv中的内容,然后客户机/ GetStuff的输出注入它

That will replace the contents of div id="myDiv" with your loading indicator, and then inject the output of Client/GetStuff into it.

这篇关于使用jQuery调用控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆