How do I start building a new component for Blazor?

Platform: Blazor| Category: Components

Blazor considers each .razor file as a new component. The component class is usually written in the form of a Razor markup page. So, you can create a new component and reuse it across the application. In the following example, a Blazor component is created in the Components folder and used in the Index.razor page. 

[BlazorComponent.razor]

<h1>@blazorHeader</h1>

    <div class="card card-body" style="width: 18rem;">
        <h5><b>@pageName</b></h5>
        <p>@pageDescription</p>
    </div>

    @code {
        private string blazorHeader = "Blazor App!";
        private string pageName = "Blazor Page";
        private string pageDescription = "Blazor component is created";
    }

[Index.razor]

@page "/"
@using BlazorApp1.Components

<BlazorComponent></BlazorComponent>

View Sample in GitHub

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.