Introduction
Here is the story of how I discovered this topic. I was trying to send multiple parameters from parent to child component, it was swell in the beginning but down the road TRex started growing, meaning bigger the application gets more the data had to be sent from parent to child component. Imagine the fishing net of all those parameters?
There has to be a better way to come across this situation and come to think of it there is one, it's called AttributeSplitting.
What is this magical word AttributeSplitting? let's take a walk to uncover the secrets of AttributeSplitting.
Following are the topics being covered in this article, in this same order!
- Why do we need Attribute-Splatting?
- What is Attribute-Splatting & How to use Attribute-Splatting?
Alright, now that we have set the agenda. let's get cracking.
Create a razor component, name it "Child.razor" as per listing 1. Ignore the style in this file, keep your eye on the input element at line number 6.
<div class="boxChild" style="width:350px;">
<h3 style="padding:5px;">Child</h3>
<form>
<label>Name:</label>
<input type="text"
height="20"
placeholder="Enter your name!"
maxlength="15"
size="25"
autofocus><br><br>
<input class="btn btn-success" type="submit" value="Submit">
</form>
</div>
<style>
.boxChild {
background-color: rgb(220, 210, 240);
border: 5px solid #123524;
width: 250px;
margin-left: 30px;
margin-bottom: 10px;
padding: 5px;
}
</style>
@code {
}
Listing 1: Child.razor
The input element on line number 6 has so many attributes such as type, height, placeholder, maxlength, size.
Let's see this in action.

Image 1: Output of Listing 1
1. Why do we need Attribute-Splatting?
The problem occurs when the parent component steps in to set these values for its child component.
Let's see how would that look like?
First, we need to have these attributes exposed for parents to access with [Parameter] and then bind these parameters to the HTML's input tag.
Let's incorporate these changes!
We've modified the input tag at line number 6 and added new parameters from line number 29 in the following listing 2.
<div class="boxChild" style="width:350px;">
<h3 style="padding:5px;">Child</h3>
<form>
<label>Name:</label>
<input type=@type
height=@height
placeholder=@placeholder
maxlength=@maxlength
size=@size
autofocus><br><br>
<input class="btn btn-success" type="submit" value="Submit">
</form>
</div>
<style>
.boxChild {
background-color: rgb(220, 210, 240);
border: 5px solid #123524;
width: 250px;
margin-left: 30px;
margin-bottom: 10px;
padding: 5px;
}
</style>
@code {
[Parameter]
public string type { get; set; }
[Parameter]
public string height { get; set; }
[Parameter]
public string placeholder { get; set; }
[Parameter]
public string maxlength { get; set; }
[Parameter]
public string size { get; set; }
}
Listing 2: Child.razor with Parameters
Now all we have to do is to create a parent component which will host Child.razor and we will set the values from parent.
In listing 3, we're doing just that! at line number 3 you can see how we are creating an instance of the child component and passing the values from the parent.




Join the conversation! Your thoughts help the community grow.