I have searched for 2 hours and couldn't find an async example of how to implement an async controller in MVC 6. All examples seem to sync controllers.
What I want to achieve is something like below. But it doesn't work:
[Route("api/[controller]")]
public class MediaController
{
[HttpGet]
public async Task<MediaList> Get()
{
Media media1 = new Media(DbContext) { Id = 1, Title = "Hello world" };
DbContext.Medias.Add(media1);
Media media2 = new Media(DbContext) { Id = 2, Title = "Hello world" };
DbContext.Medias.Add(media2);
var mediaList = await DbContext.Medias
.OrderByDescending(m => m.Id)
.Take(10)
.ToListAsync();
return mediaList;
}
I have searched for 2 hours and couldn't find an async example of how to implement an async controller in MVC 6. All examples seem to sync controllers.
What I want to achieve is something like below. But it doesn't work: