I'm new here and pretty much new in C# too. I have this code:
[Bind(Direction.ServerToClient)]
public List<AutorListModel> Autors { get; set; }
public override async Task PreRender()
{
Autors = await AutorService.GetAllAutorsAsync();
await base.PreRender();
}
And this:
public async Task<List<AutorListModel>> GetAllAutorsAsync()
{
using (var dbContext = CreateDbContext())
{
return await dbContext.Autors.Select(
s => new AutorListModel
{
Id = s.Id,
Jmeno = s.Jmeno,
Prijmeni = s.Prijmeni
}
).ToListAsync();
}
}
But AutorService.GetAllAutorsAsync();
shows this error:
An object reference is required for the non-static field, method, or property 'AutorService.GetAllAutorAsync()'
I know that it is because I want to use async method when static is required, but I don't know what to change. Does anyone have any idea what to do?