Using templated components
In constructing a Razor component, component parameters serve as the communication channels between parent and child components. While discussing nested components, we brought attention to a special ChildContent
component parameter of the RenderFragment
type. This parameter enables the parent component to set the content of the child component. For instance, the content of MenuItem
in the following code can be assigned an HTML string:
<MenuItem Id="@_dialogDeleteId">
<strong>Delete</strong>
</MenuItem>
We are able to achieve this as MenuItem
defines the following component parameter, which can be observed in Listing 10.11:
[Parameter]
public RenderFragment ChildContent { get; set; }
If we want to explicitly specify the ChildContent
parameter, we can achieve this as follows:
<MenuItem Id="@_dialogDeleteId">
<ChildContent>
<strong>Delete</strong>
</ChildContent...