JavaScript Interop in Blazor: Call JS from C# and C# from JS
Blazor JavaScript interop runs both ways. From C#, inject IJSRuntime and await InvokeVoidAsync (no result) or InvokeAsync<T> (a result). From JavaScript, call a C# method marked [JSInvokable] with DotNet.invokeMethodAsync. The catch is timing: there’s no browser during prerendering, so JS calls belong in OnAfterRenderAsync. I ran every pattern below on .NET 10, in one checkout … Read more >>