Browser Integration in Blazor

Browser Integration is the fifth chapter of the free Blazor tutorial. It shows how your Blazor app works together with the browser and with JavaScript.

What each lesson covers:

  • JavaScript Interop: When to use JS interop, adding JavaScript files, calling JavaScript from C# (IJSRuntime, async and sync calls, modules, timing), calling C# from JavaScript ([JSInvokable], DotNetObjectReference), practical uses, JSException and disposing references.

Every code box compiles your components with the real Razor compiler and runs them on .NET 10 in your browser.

Lessons in this section

  1. JavaScript Interop

    JavaScript interop in Blazor: when to use it, adding JavaScript files, IJSRuntime with InvokeAsync and InvokeVoidAsync, arguments and return values, sync calls, modules, interop timing, [JSInvokable] and DotNetObjectReference, JSException and disposing references.

    • Add JavaScript files and call them with IJSRuntime
    • Pass values to JavaScript and read the results
    • Load JavaScript modules and call JavaScript at the right time
    • Call C# from JavaScript, handle errors and dispose references