MSDN Documentation

Microsoft Developer Network

Getting Started with Blazor

Welcome to the Blazor learning path! Blazor is a free, open-source web framework for building interactive client-side web UIs with .NET. This tutorial will guide you through the initial steps to create your first Blazor application.

What is Blazor?

Blazor allows you to build web UIs using C# and .NET instead of JavaScript. It supports two main hosting models:

This guide will focus on getting you started with Blazor using the recommended Blazor WebAssembly model for a client-side experience.

Prerequisites

Before you begin, ensure you have the following installed:

Creating Your First Blazor App

Let's create a new Blazor WebAssembly project. Open your terminal or command prompt and navigate to the directory where you want to create your project. Then, run the following .NET CLI command:

dotnet new blazorwasm -o MyBlazorApp

This command will create a new directory named MyBlazorApp containing the structure of a basic Blazor WebAssembly application.

Running Your Blazor App

Navigate into your new project directory and run the application:

cd MyBlazorApp
dotnet run

Your browser should automatically open to https://localhost:xxxx (where xxxx is a port number). You'll see the default Blazor template application, which includes a counter and a fetch data page.

Understanding the Project Structure

Here's a quick overview of the key files and folders in your project:

Important: Blazor components are typically written in Razor files (.razor), which combine HTML markup with C# code.

Next Steps

Congratulations! You've successfully created and run your first Blazor application. Now you're ready to dive deeper: