Attribute Splatting and Arbitrary Parameters in Blazor

Components can capture and render additional attributes in addition to the component’s declared parameters. Additional attributes can be captured in a dictionary and then splatted onto an element when the component is rendered using the @attributes Razor directive attribute. This scenario is useful for defining a component that produces a markup element that supports a variety of customizations.

[Parameter(CaptureUnmatchedValues =true)]
public Dictionary<string, object> 
ArbitraryAttributeDictionary { get; set; }



<div @attributes="TextAttributes">

@code {

    public string Value { get; set; }

    [Parameter(CaptureUnmatchedValues = true)]
    public Dictionary<string, object> TextAttributes  { get; set; }



@page "/"

<DummyText Value="Hello World" Title="Hi"></DummyText>