异步控制器返回" System.Threading.Tasks.Task`1 [System.Web.Mvc.ActionResult] QUOT; [英] Async Controller Returning "System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult]"
问题描述
我试图找出为什么一把umbraco 7.2.4似乎并不在我的ASP.NET MVC控制器来处理异步任务。我觉得像我读过几乎每一个可能的堆栈溢出,并一把umbraco Q&放大器;一个,并试图尽可能多的方法来尽量缩小问题。这是既为一把umbraco 7和; MVC 4和放大器; MVC 5.工作得很好,在MVC项目,而不一把umbraco。
HomeController.cs:
使用System.Threading.Tasks;
使用System.Web.Mvc;
使用Umbraco.Web.Models;
使用Umbraco.Web.Mvc;命名空间Umbraco.Async.Website.Controllers
{
公共类HomeController的:RenderMvcController
{
公开新异步任务<&的ActionResult GT;指数(RenderModel模型)
{
VAR menuModel =新HomeViewModel(模型);
等待Task.Delay(1000);
返回视图(家,menuModel);
}
} 公共类HomeViewModel:RenderModel
{
公共字符串测试=比萨是真棒!!!!; 公共HomeViewModel(RenderModel模型)
:基地(model.Content,model.CurrentCulture)
{ }
}
}
Home.cshtml:
@ * @继承Umbraco.Web.Mvc.UmbracoTemplatePage * @
@inherits UmbracoViewPage< Umbraco.Async.Website.Controllers.HomeViewModel>
@ {
布局= NULL;
}< H1> @ Model.Test< / H1>
在结束浏览器不显示渲染视图,只是文本字符串:
System.Threading.Tasks.Task`1 [System.Web.Mvc.ActionResult]
块引用>解决方案我已经提出了与一把umbraco一个问题,对于这个问题,因为我已经奔这个苦苦挣扎了好一阵。我已经写放在这里但简而言之,你可以使用它代替:
公共异步任务<&的ActionResult GT;首页(RenderModel模型)
{
VAR menuModel =新HomeViewModel(模型);
等待Task.Delay(1000);
返回视图(家,menuModel);
}的区别是,
首页
行动需要precedence过失败的指标作用,因为它是从模板名称不是文档类型别名路由。I'm trying to work out why Umbraco 7.2.4 just doesn't seem to handle asynchronous tasks in my ASP.NET MVC controller. I feel like I've read almost every possible stack overflow and umbraco q&a, and tried many possible methods to try narrow down the problem. This is both for Umbraco 7 & MVC 4 and & MVC 5. It works just fine in an MVC project without Umbraco.
HomeController.cs:
using System.Threading.Tasks; using System.Web.Mvc; using Umbraco.Web.Models; using Umbraco.Web.Mvc; namespace Umbraco.Async.Website.Controllers { public class HomeController : RenderMvcController { public new async Task<ActionResult> Index(RenderModel model) { var menuModel = new HomeViewModel(model); await Task.Delay(1000); return View("Home", menuModel); } } public class HomeViewModel : RenderModel { public string Test = "Pizza is awesome!!!!"; public HomeViewModel(RenderModel model) : base(model.Content, model.CurrentCulture) { } } }
Home.cshtml:
@*@inherits Umbraco.Web.Mvc.UmbracoTemplatePage*@ @inherits UmbracoViewPage<Umbraco.Async.Website.Controllers.HomeViewModel> @{ Layout = null; } <h1>@Model.Test</h1>
In the end the browser shows no rendered view, and just the text string:
System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult]
解决方案I've raised an issue with Umbraco for this issue as I have ben struggling with this for quite a while. I have written an article on a solution here but in a nutshell you can use this instead:
public async Task<ActionResult> Home(RenderModel model) { var menuModel = new HomeViewModel(model); await Task.Delay(1000); return View("Home", menuModel); }
The difference being that the
Home
action takes precedence over the failing Index action as it is routed from the template name not the document type alias.这篇关于异步控制器返回&QUOT; System.Threading.Tasks.Task`1 [System.Web.Mvc.ActionResult] QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!