After digging deeper, I guess I have found a solution.
You'll need to add AddInteractiveServerComponents()
and AddInteractiveServerRenderMode()
in your Program.cs
file.
it turns out, AddInteractiveServerComponents()
method enables server-side interactions for components and AddInteractiveServerRenderMode()
method allows the components to handle server-side events.
Program.cs
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
...
...
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
Then, add @rendermode InteractiveServer
at the top of your component:
This worked for me!