MVC3 - 阿贾克斯加载图标 [英] MVC3 - Ajax loading icon
问题描述
我想这可能需要几秒钟时间来处理一个ActionResult的请求期间展现一个ajax加载图标。
I would like to show an ajax loading icon during a ActionResult request that can take a few seconds to process.
什么是最好的方式来实现这一点?
What is the best approach to accomplished this?
我只想要显示的图标建造它验证通过后,(我用MVC3,EF code首先,使验证自动把页)。
I only want to display the icon after the built it validation passes (I am using MVC3, EF Code First, so the validation is automatically put on the page).
有可能进一步验证/对的ActionResult时例外,在这种情况下,消息显示给用户,然后我想加载图标再次消失了。
There may be further validation/exceptions during the ActionResult, in which case a message is displayed to the user, and I'd then want the loading icon to disappear again.
谢谢!
推荐答案
链路定义为一个Ajax动作链接和某个指定网页上的旋转GIF的ID。
Define your link as an Ajax action link and specify the ID of a spinning GIF somewhere on your page.
<div id="result"></div>
<img id="spinner" src="../content/ajaxspinner.gif" style="display: none;">
@Ajax.ActionLink("Link Text", "ActionName", "ControllerName", null, new AjaxOptions{UpdateTargetId = "result", LoadingElementId = "spinner"}, null)
,或者如果它是一种形式:
or if it is a form:
@using(Ajax.BeginForm("Action", "Controller", null, new AjaxOptions{UpdateTargetId = "result", LoadingElementId = "spinner"}, null))
{
@Html.TextBox("Data")<br/>
<input type="submit" value="Submit" />
}
这篇关于MVC3 - 阿贾克斯加载图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!