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; }
Example
DummyText.razor
<div @attributes="TextAttributes"> @Value </div> @code { [Parameter] public string Value { get; set; } [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> TextAttributes { get; set; } }
Index.razor
@page "/" <DummyText Value="Hello World" Title="Hi"></DummyText>
References
https://docs.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-6.0#attribute-splatting-and-arbitrary-parameters
http://www.binaryintellect.net/articles/f52ae3dc-53fd-4342-97d1-e9cdcf47cd11.aspx