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 a public
property:
@code { Â Â Â Â [Parameter] Â Â Â Â public string MyParameter { get; set; } }
We can also do the same using a code-behind file. We can add a parameter 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 of the curly braces. To set the parameter in the @page
directive, we simply go to the URL: /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...