Exploring binding
When building applications, data is important, and we can use binding to show or change data. By using binding, you can connect variables within a component (so that it updates automatically) or by setting a component attribute. Perhaps the most fantastic thing is that by using binding, Blazor understands when it should update the UI and the variable (if the data changes in the UI).
In Blazor, there are two different ways that we can bind values to components, as follows:
- One-way binding
- Two-way binding
By using binding, we can send information between components and make sure we can update a value when we want to.
One-way binding
We have already discussed one-way binding in Chapter 4, Creating Basic Blazor Components. Let’s look at the component again and continue building on it in this section.
In this section, we will combine parameters and binding.
The Counter.razor
example looks like this:
@page "...