作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Controller 中有一个像这样的方法
public string UpdateResource()
{
Thread.Sleep(2000);
return string.Format("Current time is {0}", DateTime.Now.ToShortTimeString());
}
我的 View 页面中有一个 html 按钮,当我单击该按钮时,我希望显示一个正在加载的 gif 图像,然后在 2000 毫秒后消失。下面是我的 html
<input type="button" id="btnUpdate" value="Update" />
<img id="loading" src="/Images/ajax-loader.gif" alt="Updating ..." />
<div id="result"></div>
如何调用 Controller 方法。我已经看到了 Html.ActionLink
但我希望在单击按钮时使用它,而不是超链接。
请帮忙
最佳答案
首先更改为UpdateResource
方法。现在它返回 ActionResult:
public ActionResult UpdateResource()
{
Thread.Sleep(5000);
return Content(string.Format("Current time is {0}", DateTime.Now.ToShortTimeString()));
}
我们必须在加载文档时隐藏图像,因此我们将图像标签更改为:
<img id="loading" src="../../Content/progress.gif" alt="Updating ..." style="display: none;" />
我们添加了 style="display:none"
。
然后我们使用 jQuery:
<script type="text/javascript">
$(document).ready(
function() {
$('#btnUpdate').click(
function() {
$('#loading').show();
$.get('<%= Url.Action("UpdateResource") %>', {},
function(data) {
$('#result').html(data);
$('#loading').hide();
});
}
);
}
);
</script>
加载文档后,我们将为您的按钮设置单击操作。它显示进度,然后使用ajax 获取ActionResult。当 ActionResult 返回时,我们隐藏进度并使用返回的数据设置 #result div 的内容。
关于asp.net-mvc - 在mvc中加载gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1929497/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!