Parameters
A parameter makes it possible to send a value to a component. To add a parameter to a component, we use the [Parameter]
attribute on the public
property:
@code {
[Parameter]
public int MyParameter { get; set; }
}
The syntax for this is the same if we use a code-behind file. We can add a parameter to the route using the @page
directive by specifying it in the route:
@page "/parameterdemo/{MyParameter}"
In this case, we have to have a parameter specified with the same name as the name inside the curly braces. To set the parameter in the @page
directive, we go to /parameterdemo/THEVALUE
.
There are cases where we want to specify another type instead of a string (string is the default). We can add the data type after the parameter name like this:
@page "/parameterdemo/{MyParameter:int}"
This will match the route only if the data type is an integer. We can also pass parameters using cascading parameters. We can also have...