What is Blazor and what is Razor?

What is Blazor and what is Razor?


Blazor is a single-page app framework for building interactive client-side Web apps with .NET. Blazor uses open web standards without plugins or code transpilation. Blazor works in all modern web browsers, including mobile browsers.

You write C# in case of JavaScript, and you can use most of the .NET ecosystem of open source libraries. For the most part, if it's .NET Standard, it'll run in the browser. (Of course if you called a Windows API or a Linux specific API and it didn't exist in the client-side browser S world, it's not gonna work, but you get the idea).

The .NET code runs inside the context of WebAssembly. You're running "a .NET" inside your browser on the client-side with no plugins, no Silverlight, Java, Flash, just open web standards.

Following is a great diagram from the Blazor docs.

And Here's the canonical "click a button update some HTML" example.

@page "/counter"
<p>Current count: @currentCount</p>
<button class="btn btn-primary" onclick="@IncrementCount">Count</button>
@functions {
    int currentCount = 0;
    void IncrementCount()

You can see this running entirely in the browser, with the C# .NET code running on the client side. .NET DLLs (assemblies) are downloaded and executed by the CLR that's been compiled into WASM and running entirely in the context of the browser.

Note also that I'm stopped at a BREAKPOINT in C# code, except the code is running in the browser and mapped back into JS/WASM world.


Please note that if you want to open Blazor projects in Visual Studio, you must have Visual Studio 15.7 Preview 1 or later and the .NET Core 2.1 Preview 1 SDK. Recommanded: the latest Visual Studio 2019 Preview and the latest .NET Core SDK.

Note: the Blazor Visual Studio extension is not longer required since the ASP.NET Core Preview 7.

Here is the documentation of Microsoft, Get started with Blazor.

Get started with ASP.NET Core Blazor


User Comment

Loading comments..