问题描述
我在没有异步方法的asp.net core 3.1中使用了徽章这是我的服务代码
public int GetNotSeenContact()
{
return _context.Contacts.Where(s => s.Seen == false).Count();
}
这是作用域布局中的调用:
public int GetContactCont()
{
return _admin.GetNotSeenContact();
}
这是我使用它的地方:
int ConactBell = scope.GetContactCont();
<span class="badge badge-pill badge-warning notification">@ConactBell</span>
这工作得很好,但是当我使用 Async 方法实现它时,它显示此异常而不是用户编号:
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[system.int32,DIG.Core.Classes.PanelLayoutScope+<GetContactCont>d__3]
public async Task<int> GetNotSeenContact()
{
return await _context.Contacts.Where(s => s.Seen == false).CountAsync();
}
这是在我的范围类中:
public async Task<int> GetContactCont()
{
return await _admin.GetNotSeenContact();
}
@inject PanelLayoutScope scope
@{
Task<int> ConactBell = scope.GetContactCont();}
我的 html 代码:
<span class="badge badge-pill badge-warning notification">@ConactBell</span>
请给我最好的解决方案,并告诉我为什么当我使用 Async 方法时会发生这种情况。非常感谢!