Building components using Blazor Server
In this section, we will build a component to list, create, and edit customers in the Northwind database. We will build it first for Blazor Server naively, and then refactor it to work with both Blazor Server and Blazor WebAssembly.
Defining and testing a simple component
We will add the new component to the existing Blazor Server project:
- In the
Northwind.BlazorServer
project (not theNorthwind.BlazorWasm.Server
project), in thePages
folder, add a new file namedCustomers.razor
. In Visual Studio, the project item is named Razor Component.Good Practice: Component filenames must start with an uppercase letter, or you will have compile errors!
- Add statements to output a heading for the
Customers
component and define a code block that defines a property to store the name of a country, as shown in the following markup:<h3>Customers@(string.IsNullOrWhiteSpace(Country) ? " Worldwide...