Reputation: 1598
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
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
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