HTML Invoker Commands in Blazor
Stop Using JS for Things the Browser Already Handles Blazor makes handling UI events in C# almost effortless. Because of that, it’s tempting to default to @onclick , component state flags, conditional rendering, and JS Interop for every basic interaction. But modern HTML has caught up. The browser now handles many of the small UI toggles we used to build manually. One of the most useful recent additions to web standards is HTML Invoker Commands . Invoker Commands allow an HTML element (usually a button) to declaratively tell another element to perform an action. For example, opening a modal: HTML < button commandfor = "detailsDialog" command = "show-modal" > View Details </ button > Notice what’s missing here: No JavaScript event listeners No Blazor @onclick handlers No bool _isOpen flags tracking visibility No JS Interop calls The browser manages the interaction directly. For Blazor developers, this brings up an important architectural ques...