-
Book Overview & Buying
-
Table Of Contents
Blazor WebAssembly by Example - Third Edition
By :
Attribute splatting lets you pass multiple attributes as a dictionary instead of defining each one individually.
When a child component has many parameters, assigning each value individually in markup can be tedious and repetitive. Attribute splatting solves this problem by letting you pass a group of attributes as a single object instead of setting each parameter one by one.
With attribute splatting, unmatched attributes are captured in a Dictionary<string, object> and passed to the component as a unit. You then reference that dictionary in markup using the @attributes directive. At render time, Blazor "splats" (expands) each key/value pair in the dictionary into a separate attribute on the component or HTML element.
The following code is for a custom button component called BweButton that has many parameters:
BweButton.razor
<button type="@Type"
class="@Class"
disabled="@Disabled"
title="...