A razor page is currently constructing a page like this:
@*...*@
<Template>
<Items>
<Foo />
@foreach (var pin in Helper.GetPins()) {
@*... using pin in control with custom template etc.. *@
}
<Bar />
</Items>
</Template>
@*...*@
The method in Helper.GetPins()
looks like this:
public IEnumerable<Pin> GetPins() {
_PinData = DataHelper.SynchronousRequest();
return _PinData;
}
Now I have made my GetPins async:
public async Task<IEnumerable<Pin>> GetPinsAsync() {
_PinData = await DataHelper.AsyncRequest();
return _PinData;
}
Is it possible to use this GetPinsAsync like this in my Blazor razor page?
If so, how should this be done? Like this:
@foreach (var pin in Helper.GetPinsAsync()) {
@*... using pin in control with custom template etc.. *@
}
Or should something like await foreach
be used?
https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#asynchronous-streams