I have an async method in razor page of a blazor server app.
What I am trying to achieve is as below but of course await requires async. How can I await async method here?
@{
var result = await Test(local);
<div>
@result
</div>
}
This does not work. It says "cannot convert lambda expression to type 'object' because it is not a delegate type".
<div class="line">
@(async (local) => { await Test(local); })
</div>
It's better to use component life cycle events. You can to do something like
<div class="line">
@result
</div>
@code{
private string result;
protected async override Task OnInitializedAsync()
{
result = await Test(local);
}
}
See Blazor documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With