Skip to content

Commit f81eefa

Browse files
authored
Blazor Overview topic UE pass (#20005)
1 parent ca8abdc commit f81eefa

2 files changed

Lines changed: 39 additions & 41 deletions

File tree

aspnetcore/blazor/index.md

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Explore ASP.NET Core Blazor, a way to build interactive client-side
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: "mvc, seoapril2019"
8-
ms.date: 06/19/2020
8+
ms.date: 09/25/2020
99
no-loc: ["ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR]
1010
uid: blazor/index
1111
---
@@ -15,102 +15,98 @@ By [Daniel Roth](https://github.com/danroth27) and [Luke Latham](https://github.
1515

1616
*Welcome to Blazor!*
1717

18-
Blazor is a framework for building interactive client-side web UI with .NET:
18+
Blazor is a framework for building interactive client-side web UI with [.NET](/dotnet/standard/tour):
1919

20-
* Create rich interactive UIs using C# instead of JavaScript.
20+
* Create rich interactive UIs using [C#](/dotnet/csharp/) instead of [JavaScript](https://www.javascript.com).
2121
* Share server-side and client-side app logic written in .NET.
2222
* Render the UI as HTML and CSS for wide browser support, including mobile browsers.
2323
* Integrate with modern hosting platforms, such as [Docker](/dotnet/standard/microservices-architecture/container-docker-introduction/index).
2424

2525
Using .NET for client-side web development offers the following advantages:
2626

2727
* Write code in C# instead of JavaScript.
28-
* Leverage the existing .NET ecosystem of .NET libraries.
28+
* Leverage the existing .NET ecosystem of [.NET libraries](/dotnet/standard/class-libraries).
2929
* Share app logic across server and client.
3030
* Benefit from .NET's performance, reliability, and security.
31-
* Stay productive with Visual Studio on Windows, Linux, and macOS.
31+
* Stay productive with [Visual Studio](https://visualstudio.microsoft.com) on Windows, Linux, and macOS.
3232
* Build on a common set of languages, frameworks, and tools that are stable, feature-rich, and easy to use.
3333

3434
## Components
3535

3636
Blazor apps are based on *components*. A component in Blazor is an element of UI, such as a page, dialog, or data entry form.
3737

38-
Components are .NET classes built into .NET assemblies that:
38+
Components are .NET C# classes built into [.NET assemblies](/dotnet/standard/assembly/) that:
3939

4040
* Define flexible UI rendering logic.
4141
* Handle user events.
4242
* Can be nested and reused.
4343
* Can be shared and distributed as [Razor class libraries](xref:razor-pages/ui-class) or [NuGet packages](/nuget/what-is-nuget).
4444

45-
The component class is usually written in the form of a [Razor](xref:mvc/views/razor) markup page with a `.razor` file extension. Components in Blazor are formally referred to as *Razor components*. Razor is a syntax for combining HTML markup with C# code designed for developer productivity. Razor allows you to switch between HTML markup and C# in the same file with [IntelliSense](/visualstudio/ide/using-intellisense) support. Razor Pages and MVC also use Razor. Unlike Razor Pages and MVC, which are built around a request/response model, components are used specifically for client-side UI logic and composition.
45+
The component class is usually written in the form of a [Razor](xref:mvc/views/razor) markup page with a `.razor` file extension. Components in Blazor are formally referred to as *Razor components*. Razor is a syntax for combining HTML markup with C# code designed for developer productivity. Razor allows you to switch between HTML markup and C# in the same file with [IntelliSense](/visualstudio/ide/using-intellisense) programming support in Visual Studio. Razor Pages and MVC also use Razor. Unlike Razor Pages and MVC, which are built around a request/response model, components are used specifically for client-side UI logic and composition.
4646

47-
The following Razor markup demonstrates a component (`Dialog.razor`), which can be nested within another component:
47+
Blazor uses natural HTML tags for UI composition. The following Razor markup demonstrates a component (`Dialog.razor`) that displays a dialog and processes an event when the user selects a button:
4848

4949
```razor
50-
<div>
51-
<h1>@Title</h1>
52-
53-
@ChildContent
54-
55-
<button @onclick="OnYes">Yes!</button>
50+
<div class="card" style="width:22rem">
51+
<div class="card-body">
52+
<h3 class="card-title">@Title</h3>
53+
<p class="card-text">@ChildContent</p>
54+
<button @onclick="OnYes">Yes!</button>
55+
</div>
5656
</div>
5757
5858
@code {
5959
[Parameter]
60-
public string Title { get; set; }
60+
public RenderFragment ChildContent { get; set; }
6161
6262
[Parameter]
63-
public RenderFragment ChildContent { get; set; }
63+
public string Title { get; set; }
6464
6565
private void OnYes()
6666
{
67-
Console.WriteLine("Write to the console in C#! 'Yes' button was selected.");
67+
Console.WriteLine("Write to the console in C#! 'Yes' button selected.");
6868
}
6969
}
7070
```
7171

72-
The dialog's body content (`ChildContent`) and title (`Title`) are provided by the component that uses this component in its UI. `OnYes` is a C# method triggered by the button's `onclick` event.
73-
74-
Blazor uses natural HTML tags for UI composition. HTML elements specify components, and a tag's attributes pass values to a component's properties.
75-
76-
In the following example, the `Index` component uses the `Dialog` component. `ChildContent` and `Title` are set by the attributes and content of the `<Dialog>` element.
72+
In the preceding example, `OnYes` is a C# method triggered by the button's `onclick` event. The dialog's text (`ChildContent`) and title (`Title`) are provided by the following component that uses this component in its UI.
7773

78-
`Pages/Index.razor`:
74+
The `Dialog` component is nested within another component using an HTML tag. In the following example, the `Index` component (`Pages/Index.razor`) uses the preceding `Dialog` component. The tag's `Title` attribute passes a value for the title to the `Dialog` component's `Title` property. The `Dialog` component's text (`ChildContent`) are set by the content of the `<Dialog>` element. When the `Dialog` component is added to the `Index` component, [IntelliSense in Visual Studio](/visualstudio/ide/using-intellisense) speeds development with syntax and parameter completion.
7975

8076
```razor
8177
@page "/"
8278
8379
<h1>Hello, world!</h1>
8480
85-
Welcome to your new app.
81+
<p>
82+
Welcome to your new app.
83+
</p>
8684
87-
<Dialog Title="Blazor">
85+
<Dialog Title="Learn More">
8886
Do you want to <i>learn more</i> about Blazor?
8987
</Dialog>
9088
```
9189

92-
The dialog is rendered when the parent (`Pages/Index.razor`) is accessed in a browser:
90+
The dialog is rendered when the `Index` component is accessed in a browser. When the button is selected by the user, the browser's developer tools console shows the message written by the `OnYes` method:
9391

94-
![Dialog component rendered in the browser](index/_static/dialog.png)
92+
![Dialog component rendered in the browser nested inside of the Index component. The browser developer tools console shows the message written by C# code when the user selects the Yes! button in the UI.](index/_static/dialog.png)
9593

96-
When this component is used in the app, IntelliSense in [Visual Studio](/visualstudio/ide/using-intellisense) and [Visual Studio Code](https://code.visualstudio.com/docs/editor/intellisense) speeds development with syntax and parameter completion.
97-
98-
Components render into an in-memory representation of the browser's Document Object Model (DOM) called a *render tree*, which is used to update the UI in a flexible and efficient way.
94+
Components render into an in-memory representation of the browser's [Document Object Model (DOM)](https://developer.mozilla.org/docs/Web/API/Document_Object_Model/Introduction) called a *render tree*, which is used to update the UI in a flexible and efficient way.
9995

10096
## Blazor WebAssembly
10197

102-
Blazor WebAssembly is a single-page app framework for building interactive client-side web apps with .NET. Blazor WebAssembly uses open web standards without plugins or code transpilation and works in all modern web browsers, including mobile browsers.
98+
Blazor WebAssembly is a [single-page app (SPA) framework](/dotnet/architecture/modern-web-apps-azure/choose-between-traditional-web-and-single-page-apps) for building interactive client-side web apps with .NET. Blazor WebAssembly uses open web standards without plugins or recompiling code into other languages. Blazor WebAssembly works in all modern web browsers, including mobile browsers.
10399

104100
Running .NET code inside web browsers is made possible by [WebAssembly](https://webassembly.org) (abbreviated `wasm`). WebAssembly is a compact bytecode format optimized for fast download and maximum execution speed. WebAssembly is an open web standard and supported in web browsers without plugins.
105101

106-
WebAssembly code can access the full functionality of the browser via JavaScript, called *JavaScript interoperability* (or *JavaScript interop*). .NET code executed via WebAssembly in the browser runs in the browser's JavaScript sandbox with the protections that the sandbox provides against malicious actions on the client machine.
102+
WebAssembly code can access the full functionality of the browser via JavaScript, called *JavaScript interoperability*, often shortened to *JavaScript interop* or *JS interop*. .NET code executed via WebAssembly in the browser runs in the browser's JavaScript sandbox with the protections that the sandbox provides against malicious actions on the client machine.
107103

108104
![Blazor WebAssembly runs .NET code in the browser with WebAssembly.](index/_static/blazor-webassembly.png)
109105

110106
When a Blazor WebAssembly app is built and run in a browser:
111107

112108
* C# code files and Razor files are compiled into .NET assemblies.
113-
* The assemblies and the .NET runtime are downloaded to the browser.
109+
* The assemblies and the [.NET runtime](/dotnet/framework/get-started/overview) are downloaded to the browser.
114110
* Blazor WebAssembly bootstraps the .NET runtime and configures the runtime to load the assemblies for the app. The Blazor WebAssembly runtime uses JavaScript interop to handle DOM manipulation and browser API calls.
115111

116112
The size of the published app, its *payload size*, is a critical performance factor for an app's useability. A large app takes a relatively long time to download to a browser, which diminishes the user experience. Blazor WebAssembly optimizes payload size to reduce download times:
@@ -133,32 +129,34 @@ The size of the published app, its *payload size*, is a critical performance fac
133129

134130
## Blazor Server
135131

136-
Blazor decouples component rendering logic from how UI updates are applied. Blazor Server provides support for hosting Razor components on the server in an ASP.NET Core app. UI updates are handled over a [SignalR](xref:signalr/introduction) connection.
132+
Blazor decouples component rendering logic from how UI updates are applied. *Blazor Server* provides support for hosting Razor components on the server in an ASP.NET Core app. UI updates are handled over a [SignalR](xref:signalr/introduction) connection.
133+
134+
The runtime handles:
137135

138-
The runtime handles sending UI events from the browser to the server and applies UI updates sent by the server back to the browser after running the components.
136+
* Sending UI events from the browser to the server.
137+
* Applying UI updates to the rendered component that are sent back by the server.
139138

140139
The connection used by Blazor Server to communicate with the browser is also used to handle JavaScript interop calls.
141140

142141
![Blazor Server runs .NET code on the server and interacts with the Document Object Model on the client over a SignalR connection](index/_static/blazor-server.png)
143142

144143
## JavaScript interop
145144

146-
For apps that require third-party JavaScript libraries and access to browser APIs, components interoperate with JavaScript. Components are capable of using any library or API that JavaScript is able to use. C# code can call into JavaScript code, and JavaScript code can call into C# code. For more information, see the following articles:
147-
148-
* <xref:blazor/call-javascript-from-dotnet>
149-
* <xref:blazor/call-dotnet-from-javascript>
145+
For apps that require third-party JavaScript libraries and access to browser APIs, components interoperate with JavaScript. Components are capable of using any library or API that JavaScript is able to use. C# code can [call into JavaScript code](xref:blazor/call-javascript-from-dotnet), and JavaScript code can [call into C# code](xref:blazor/call-dotnet-from-javascript).
150146

151147
## Code sharing and .NET Standard
152148

153-
Blazor implements [.NET Standard 2.1](/dotnet/standard/net-standard), which enables Blazor projects to reference libraries that conform to .NET Standard 2.1 or earlier specifications. .NET Standard is a formal specification of .NET APIs that are common across .NET implementations. .NET Standard class libraries can be shared across different .NET platforms, such as Blazor, .NET Framework, .NET Core, Xamarin, Mono, and Unity.
149+
Blazor implements the [.NET Standard](/dotnet/standard/net-standard), which enables Blazor projects to reference libraries that conform to .NET Standard specifications. .NET Standard is a formal specification of .NET APIs that are common across .NET implementations. .NET Standard class libraries can be shared across different .NET platforms, such as Blazor, .NET Framework, .NET Core, Xamarin, Mono, and Unity.
154150

155151
APIs that aren't applicable inside of a web browser (for example, accessing the file system, opening a socket, and threading) throw a <xref:System.PlatformNotSupportedException>.
156152

157153
## Additional resources
158154

159-
* [WebAssembly](https://webassembly.org/)
155+
* [WebAssembly](https://webassembly.org)
160156
* <xref:blazor/hosting-models>
161157
* <xref:tutorials/signalr-blazor-webassembly>
158+
* <xref:blazor/call-javascript-from-dotnet>
159+
* <xref:blazor/call-dotnet-from-javascript>
162160
* [C# Guide](/dotnet/csharp/)
163161
* <xref:mvc/views/razor>
164162
* [HTML](https://www.w3.org/html/)
52.9 KB
Loading

0 commit comments

Comments
 (0)