C#C
C#16mo ago
Caleb Weeks

Using Blazor WebAssembly for client interactions in Blazor Server

Hello all!

I'm building an admin dashboard sort of application that heavily interacts with the server, so I'm using InteractiveServer rendering by default. For small client side interactions such as a collapsible sidebar, it seems like there are a few options:
  • Use JavaScript (with or without a library such as Jquery or Alpine)
  • Use HTML + CSS "hacks" such as the checkbox method that ships with the default Blazor template
  • Use Blazor WebAssembly
I love the idea of doing as much as possible directly in Blazor, but I'm running into an issue with getting a collapsible sidebar to work. I want the functionality of the collapsing sidebar to live in Blazor WebAssembly so that it isn't talking to the server just to toggle a single piece of state. But the contents of the sidebar should be a Blazor Server component so I can directly access the database (through a service), and don't need to expose an API. I tried creating a Blazor component with RenderFragments, but I'm getting that issue where they can't be serialized.

So, my question is, in an environment that is primarily tightly coupled to the server, what's the best way of sprinkling in some client side interactivity? Is it possible to just use WebAssembly for this, or should I just be using JavaScript?

Thanks!
Was this page helpful?