Blazor Component Reusability

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

In Blazor, you can easily add and reuse any component in other components by declaring them using HTML element syntax. The markup for using a component looks like an HTML tag where the name of the tag is the component type.

The following markup renders a Counter (counter.cshtml) instance.

<Counter />

Let's add this markup to the Home (index.cshtml) component.

@page "/"

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

<Counter />

Now you can see the counter component on home page.

image

Got any Blazor Question?