Solution Review: Blazor Parameters

The solution to the challenge of passing parameters to Razor components.

We'll cover the following

To make the increment count configurable in the Counter Razor component, we added an integer Increment property with the public access modifier and the [Parameter] attribute. It can be found on lines 18–19 in the project setup below. We then need to increment the value of the currentCount field by the value of this property in the IncrementCount method. It can be seen on line 25 of the Counter.razor file.

We then need to add the Increment attribute to the opening tag of the <Counter> element in the Index.razor file and set its value to 10. This is done on line 3 of the Index.razor file.

Finally, we replace the content of the <Counter> element with <h2>Every click increments the count by 10</h2> in the Index.razor file. This is done on line 4.


The complete solution can be found below.

Get hands-on with 1200+ tech skills courses.