Is it possible to await
on tasks in Razor .cshtml views?
By default it complains that it can only be used in methods marked with async
so I
No, that's not possible and you shouldn't need to do it anyway. Razor views should contain markup and at most some helper call. async/await belongs to your backend logic.
Following on MaxP's answer, it's easy to return a value from that code, despite Knagis comment:
@{
int x = DoAsyncStuffWrapper().Result;
}
@functions {
async Task<int>DoAsyncStuffWrapper()
{
await DoAsyncStuff();
}
}