-
Book Overview & Buying
-
Table Of Contents
Blazor WebAssembly by Example - Third Edition
By :
In the preceding example, you used explicit parameters for BweButton's attributes. A much more flexible way to assign values to attributes is to use arbitrary parameters. Reusable wrapper components (like custom buttons, cards, or form inputs) benefit most from this approach, as they can accept any HTML attributes or custom props without predefined properties.
Arbitrary parameters capture any unmatched attributes automatically without requiring explicit properties for each one. They use the [Parameter(CaptureUnmatchedValues = true)] attribute applied to a Dictionary<string, object> parameter. Blazor automatically captures all attributes passed to the component that don't match explicit parameters and stores them in that dictionary.
The following code is for a custom button component called BweButton2 that uses arbitrary parameters:
BweButton2.razor
<button @attributes="InputAttributes" >
@ChildContent
</button>
@code {
...