user5389726598465
user5389726598465

Reputation: 1598

Why does this handler not return anything?

I'm just starting the ASP.NET tutorial and I don't understand why there is no return statement in the method:

public async Task OnGetAsync()
{
    Movie = await _context.Movie.ToListAsync();
}

Are one line methods automatically returned like arrow statements or does it have to do with the Task in ASP?

Upvotes: 1

Views: 96

Answers (2)

sifa vahora
sifa vahora

Reputation: 117

if you want to return the list of Movie then your function should be :

public async Task<List<Movie>> OnGetAsync()
{
    return await _context.Movie.ToListAsync();
}

Upvotes: 0

tlt
tlt

Reputation: 15221

Its a model that have property Movie. That property gets set when method OnGetAsync is called. So, you don't need return.

Method return type is Task because it has await. Its analogous to void type if it would be a sync method.

Upvotes: 2

Related Questions