I have used badge in asp.net core 3.1 without Async method this is my code in service
public int GetNotSeenContact()
{
return _context.Contacts.Where(s => s.Seen == false).Count();
}
and this is call in scope layout :
public int GetContactCont()
{
return _admin.GetNotSeenContact();
}
and this is the place that I use this:
int ConactBell = scope.GetContactCont();
and this is my html code that I called :
<span class="badge badge-pill badge-warning notification">@ConactBell</span>
this is working very well but when I make it with Async method, it shows this exception instead of number for user:
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[System.Int32,DIG.Core.Classes.PanelLayoutScope+<GetContactCont>d__3]
Now these are my codes in async method in service:
public async Task<int> GetNotSeenContact()
{
return await _context.Contacts.Where(s => s.Seen == false).CountAsync();
}
this is in my scope class:
public async Task<int> GetContactCont()
{
return await _admin.GetNotSeenContact();
}
and this is the code where I use it inside html code:
@inject PanelLayoutScope scope
@{
Task<int> ConactBell = scope.GetContactCont();}
my html code :
<span class="badge badge-pill badge-warning notification">@ConactBell</span>
Please give me the best solution and tell me why does this happen when I use Async method. Thank you so much!