I'm trying to figure out why I can't get the OnAfterRenderAsync method in the Blazor.
I can't seem to find a solution after trying multiple options and looking through Microsoft docs, I'm sure I'm missing something but I can't figure out what the issue is.
In the code below, the OnInit function is getting called, but the render ones aren't.
<h1>OnInit & OnInitAsync Demo</h1>
@foreach (var item in EventType)
{
@item
<hr />
}
@code{
List<string> EventType = new List<string>();
protected override void OnInitialized()
{
EventType.Add("Initilaized");
}
protected override void OnAfterRender(bool firstRender)
{
EventType.Add("OnAfterRender is called");
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
EventType.Add("OnAfterRenderAsync is called");
await Task.Delay(1000);
}
}
This my .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>
And this is my _Host.cshtml
<app>
<component type="typeof(App)" render-mode="ServerPrerendered" />
</app>
I've also tried it this way
@(await Html.RenderComponentAsync<App>(RenderMode.ServerPrerendered))
Why aren't the events being triggered?
I had this problem, but in the component I changed my rendermode:
@rendermode InteractiveServer
Now, it's working very well.
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