【问题标题】:Definition without GetAwaiter (Razor, MVC) [duplicate]没有 GetAwaiter 的定义(Razor,MVC)[重复]
【发布时间】:2020-04-25 18:12:28
【问题描述】:

我得到了以下课程:

public class AllRegistrationsViewComponent : ViewComponent
{
 private readonly UserManager<IdentityUser> um;
 private readonly MyContext myContext;

 public AllRegistrationsViewComponent(UserManager<IdentityUser> um, MyContext myContext)
 {
   this.um = um;
   this.myContext= myContext;
 }

 public async Task<IViewComponentResult> Invoke()
 {
   var allUsers= await um.Users.ToList();
   return View(allUsers);
 }
}

我收到以下消息:

List <IdentityUser> does not contain a definition for GetAwaiter and no accessible method 
GetAwaiter accepting a first argument of type List<IdentityUser> could be found

【问题讨论】:

标签: asp.net-mvc asp.net-core razor async-await task


【解决方案1】:

只需更改此行

 var allUsers= await um.Users.ToList();

var allUsers= await um.Users.ToListAsync();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-24
    • 2011-06-16
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 2012-08-04
    相关资源
    最近更新 更多