Search⌘ K
AI Features

Component Structure

Explore the structure of Blazor WebAssembly components by learning about Razor directives, HTML markup with C# integration, and code blocks. Understand how these elements come together to build reusable components in your web applications.

We'll cover the following...

The following diagram shows code from the Counter component of the Demo project that we will create in this chapter:

Component structure
Component structure

The code in the preceding example is divided into three sections:

  • Directives
  • Markup
  • Code block

Each of the sections has a different purpose.

Directives

Directives are used to add special functionality, such as routing, layout, and dependency injection. They are defined within Razor and we cannot define own own directives.

In the preceding example, there is only one directive used—the @page directive. The @page directive is ...