ASP.Net MVC 加载进度指示器
我有一个 MVC 控制器,它运行一个进程,设置一些视图数据,然后在视图中将该数据的结果返回给用户。 处理时间取决于正在处理的数据量。 我需要一种好方法来在进程运行时在视图中显示动画 .gif,让用户知道正在发生某些事情。
我已经研究了各种 AJAX 方法和部分视图,但仍然找不到完成此任务的好方法。 我真正希望我能做的是有一个 ActionFilter,它会在显示此动画 .gif 的 OnActionExecuting 事件期间返回视图或部分视图,然后一旦控制器完成处理并返回 ViewData,即具有实际视图的视图或部分视图可以显示数据。
jQuery 似乎还能够提供一种很好的异步方式来在后台调用控制器操作,然后渲染视图。 任何帮助,将不胜感激。
I have an MVC Controller that runs through a process, sets some View Data, and then returns the results of this data back to the user in a View. The process time is dependent on the amount of data that is being processed. I need a good way to display an animated .gif within the View while the process is running, letting the user know that something is going on.
I've looked at various AJAX methods and partial views but still cannot find a good way to accomplish this. What I really wished I could do was have an ActionFilter that would return a View or Partial View during the OnActionExecuting event that displays this animated .gif, then once the Controller completed processsing and returned the ViewData, the view or partial view with the actual View Data could be displayed.
It also seems like jQuery would be able to provide a nice asynchronous way to call the controller action in the background and then render the View. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的控制器中:
在视图中(javascript,使用 JQuery):
请注意,这假定“id”位于操作之后的路线。 操作中的“x”参数是为了阻止 IE 中的激进缓存。
在视图(标记)中:
在此处获取加载程序 gif。
另请注意,您不必使用 Json 执行此操作。 如果您愿意,您可以从控制器操作中获取其他内容,例如 HTML 或 XML。
In your controller:
In the view (javascript, using JQuery):
Note that this assumes a route where 'id' comes after action. The 'x' parameter on the action is to defeat aggressive caching in IE.
In the view (markup):
Get loader gifs here.
Also note that you do not have to do this with Json. You can fetch other things like HTML or XML from the controller action if you prefer.