Building components using Blazor Server
In this section we will build a component to list, create, and edit customers in the Northwind
database.
Defining and testing a simple component
We will add the new component to the existing Blazor Server project:
- In the
NorthwindBlazorServer
project, add a new file to thePages
folder namedCustomers.razor
.Good Practice: Component filenames must start with an uppercase letter or you will see compile errors!
- Add statements to register
/customers
as its route, output a heading for the customers component, and define a code block, as shown in the following markup:@page "/customers" <h1>Customers</h1> @code { }
- In the
Shared
folder, openNavMenu.razor
and add a list item element for our new component labeledCustomers
that uses an icon of people, as shown in the following markup:<li class="nav-item px-3"> <NavLink...