在MVC中异步页面加载 [英] Async page load in mvc
问题描述
在mvc应用程序中,有一个视图,视图中某些部分的数据在服务器端占用时间,因此我需要先加载视图的另一部分,然后在该过程完成时加载其余部分.
Im mvc application,there is a some view, data of some portion in view is taking time at the server end, so I need to load the other part of the view first and when the process completes the remaining portion will load.
为此,我创建了一个局部视图,该局部视图动作是异步的,并返回一个任务.但是在Mvc 5中,我无法在视图中使用await关键字.我为mvc 6解决了这个问题.
For this I have create a partial view the partial view action is async and returns a task. But in Mvc 5 I cant use await keyword in view. I sesrch for that mvc 6 is fix this issue.
所以现在我通过使用ajax调用来加载部分视图.但是我可以不用ajax调用.或具有c#异步编程功能.
So now I am loading the partial view by using ajax call. But can I do without ajax call. Or with c# async programming feature.
推荐答案
您必须在顶级动作中的控制器中执行异步操作-在ASP.Net MVC5之前的版本中,视图动作和子动作都不能是异步的.
You have to perform async operations in controller in top level action - neither view nor child actions can be asynchronous in versions up to ASP.Net MVC5.
或者等到MVC6准备好,或者如果您允许立即使用MVC6,请- vNext .
Or wait till MVC6 is ready, or if you case allows that use MVC6 now - vNext.
这篇关于在MVC中异步页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!