是否可以使用 T4MVC 和异步操作?

Is it possible to use T4MVC and Asynchronous operations?

我的行动:

 public virtual async Task<ActionResult> IdeaDetails(int id)
        {

我的路线:

 routes.MapRoute("DesignIdeasDetails", "ideadetails/{id}",
              MVC.Designer.IdeaDetails().AddRouteValue("id", UrlParameter.Optional)

错误:Instance argument: cannot convert from 'System.Threading.Tasks.Task<System.Web.Mvc.ActionResult>' to 'System.Web.Mvc.ActionResult' C:\Work\luxedecorNew\Luxedecor\Luxedecor\App_Start\RouteConfig.cs 19 15 Luxedecor

错误 2:System.Threading.Tasks.Task<System.Web.Mvc.ActionResult>' does not contain a definition for 'AddRouteValue' and the best extension method overload 'System.Web.Mvc.T4Extensions.AddRouteValue(System.Web.Mvc.ActionResult, string, object)' has some invalid arguments

错误的发生是因为异步的工作方式。你需要在你的方法中等待任务,这样你才能得到ActionResult,像这样:

routes.MapRoute("DesignIdeasDetails", "ideadetails/{id}",
          (await MVC.Designer.IdeaDetails()).AddRouteValue("id", UrlParameter.Optional)

// or, if the method cannot be used with async/await
 routes.MapRoute("DesignIdeasDetails", "ideadetails/{id}",
          (MVC.Designer.IdeaDetails().GetAwaiter().GetResult()).AddRouteValue("id", UrlParameter.Optional)