Skip to content

Commit

Permalink
Snippet cross-links 8.0 (2) (#31274)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex committed Dec 20, 2023
1 parent 54f2bf3 commit dc64c7d
Show file tree
Hide file tree
Showing 60 changed files with 260 additions and 487 deletions.
3 changes: 2 additions & 1 deletion aspnetcore/blazor/advanced-scenarios.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This article describes the advanced scenario for building Blazor render trees ma
> [!WARNING]
> Use of <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> to create components is an *advanced scenario*. A malformed component (for example, an unclosed markup tag) can result in undefined behavior. Undefined behavior includes broken content rendering, loss of app features, and ***compromised security***.
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Manually build a render tree (`RenderTreeBuilder`)

<xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> provides methods for manipulating components and elements, including building components manually in C# code.
Expand All @@ -37,7 +39,6 @@ In <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> methods wi

```razor
@page "/built-content"
@rendermode InteractiveServer
<h1>Build a component</h1>
Expand Down
2 changes: 2 additions & 0 deletions aspnetcore/blazor/blazor-ef-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Server-side Blazor is a stateful app framework. The app maintains an ongoing con
> [!NOTE]
> This article addresses EF Core in server-side Blazor apps. Blazor WebAssembly apps run in a WebAssembly sandbox that prevents most direct database connections. Running EF Core in Blazor WebAssembly is beyond the scope of this article.
[!INCLUDE[](~/blazor/includes/location-server.md)]

## Sample app

The sample app was built as a reference for server-side Blazor apps that use EF Core. The sample app includes a grid with sorting and filtering, delete, add, and update operations. The sample demonstrates use of EF Core to handle optimistic concurrency.
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/blazor/call-web-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ zone_pivot_groups: blazor-render-modes

This article describes how to call a web API from a Blazor app.

[!INCLUDE[](~/blazor/includes/location-client-and-server-net31-or-later.md)]
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

> [!NOTE]
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the `string?`, `TodoItem[]?`, `WeatherForecast[]?`, and `IEnumerable<GitHubBranch>?` types in the article's examples.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This article explains how to flow data from an ancestor Razor component to desce
> [!NOTE]
> The code examples in this article adopt [nullable reference types (NRTs) and .NET compiler null-state static analysis](xref:migration/50-to-60#nullable-reference-types-nrts-and-net-compiler-null-state-static-analysis), which are supported in ASP.NET Core 6.0 or later. When targeting ASP.NET Core 5.0 or earlier, remove the null type designation (`?`) from the `CascadingType?`, `@ActiveTab?`, `RenderFragment?`, `ITab?`, `TabSet?`, and `string?` types in the article's examples.
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

:::moniker range=">= aspnetcore-8.0"

## Root-level cascading values
Expand Down Expand Up @@ -57,7 +59,6 @@ The following `Daleks` component displays the cascaded values.

```razor
@page "/daleks"
@rendermode InteractiveServer
<h1>Root-level cascading value registration example</h1>
Expand Down Expand Up @@ -194,6 +195,8 @@ Blazor Web Apps provide alternative approaches for cascading values that apply m
}
```

<!-- UPDATE 8.0 Check on this next instruction and confirm if it's required. -->

In the `App` component (`Components/App.razor`), adopt an interactive render mode for the entire app. The following example adopts interactive server-side rendering (interactive SSR):

```razor
Expand Down
2 changes: 2 additions & 0 deletions aspnetcore/blazor/components/control-head-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ uid: blazor/components/control-head-content

Razor components can modify the HTML `<head>` element content of a page, including setting the page's title (`<title>` element) and modifying metadata (`<meta>` elements).

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Control `<head>` content in a Razor component

Specify the page's title with the <xref:Microsoft.AspNetCore.Components.Web.PageTitle> component, which enables rendering an HTML `<title>` element to a [`HeadOutlet` component](#headoutlet-component).
Expand Down
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/data-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ uid: blazor/components/data-binding

This article explains data binding features for Razor components and DOM elements in Blazor apps.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Binding features

Razor components provide data binding features with the [`@bind`](xref:mvc/views/razor#bind) Razor directive attribute with a field, property, or Razor expression value.

The following example binds:
Expand Down
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/dynamiccomponent.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ By [Dave Brock](https://twitter.com/daveabrock)

Use the built-in <xref:Microsoft.AspNetCore.Components.DynamicComponent> component to render components by type.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Dynamic components

A <xref:Microsoft.AspNetCore.Components.DynamicComponent> is useful for rendering components without iterating through possible types or using conditional logic. For example, <xref:Microsoft.AspNetCore.Components.DynamicComponent> can render a component based on a user selection from a dropdown list.

In the following example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ uid: blazor/components/key
---
# Retain element, component, and model relationships in ASP.NET Core Blazor

This article explains how to use the `@key` directive attribute to retain element, component, and model relationships when rendering and the elements or components subsequently change.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Use of the `@key` directive attribute

When rendering a list of elements or components and the elements or components subsequently change, Blazor must decide which of the previous elements or components are retained and how model objects should map to them. Normally, this process is automatic and sufficient for general rendering, but there are often cases where controlling the process using the [`@key`](xref:mvc/views/razor#key) directive attribute is required.

Consider the following example that demonstrates a collection mapping problem that's solved by using [`@key`](xref:mvc/views/razor#key).
Expand Down
5 changes: 4 additions & 1 deletion aspnetcore/blazor/components/event-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ uid: blazor/components/event-handling

This article explains Blazor's event handling features, including event argument types, event callbacks, and managing default browser events.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Delegate event handlers

Specify delegate event handlers in Razor component markup with [`@on{DOM EVENT}="{DELEGATE}"`](xref:mvc/views/razor#onevent) Razor syntax:

* The `{DOM EVENT}` placeholder is a [DOM event](https://developer.mozilla.org/docs/Web/Events) (for example, `click`).
Expand Down Expand Up @@ -659,7 +663,6 @@ The following parent-child example demonstrates the technique.

```razor
@page "/parent-child-2"
@rendermode InteractiveServer
<Child2 OnClickCallback="@(async (value) => { await Task.Yield(); messageText = value; })" />
Expand Down
2 changes: 2 additions & 0 deletions aspnetcore/blazor/components/generic-type-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ uid: blazor/components/generic-type-support

This article describes generic type support in Razor components.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Generic type parameter support

The [`@typeparam`](xref:mvc/views/razor#typeparam) directive declares a [generic type parameter](/dotnet/csharp/programming-guide/generics/generic-type-parameters) for the generated component class:
Expand Down
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ uid: blazor/components/index

This article explains how to create and use Razor components in Blazor apps, including guidance on Razor syntax, component naming, namespaces, and component parameters.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Razor components

Blazor apps are built using *Razor components*, informally known as *Blazor components* or only *components*. A component is a self-contained portion of user interface (UI) with processing logic to enable dynamic behavior. Components can be nested, reused, shared among projects, and used in MVC and Razor Pages apps.

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.
Expand Down
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ uid: blazor/components/integration

This article explains Razor component integration scenarios for ASP.NET Core apps.

[!INCLUDE[](~/blazor/includes/location-client-and-server-net8-or-later.md)]

## Razor component integration

Razor components can be integrated into Razor Pages, MVC, and other types of ASP.NET Core apps. Razor components can also be integrated into any web app, including apps not based on ASP.NET Core, as [custom HTML elements](xref:blazor/components/js-spa-frameworks#blazor-custom-elements).

Use the guidance in the following sections depending on the project's requirements:
Expand Down
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ uid: blazor/components/layouts

This article explains how to create reusable layout components for Blazor apps.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Usefulness of Blazor layouts

Some app elements, such as menus, copyright messages, and company logos, are usually part of app's overall presentation. Placing a copy of the markup for these elements into all of the components of an app isn't efficient. Every time that one of these elements is updated, every component that uses the element must be updated. This approach is costly to maintain and can lead to inconsistent content if an update is missed. *Layouts* solve these problems.

A Blazor layout is a Razor component that shares markup with components that reference it. Layouts can use [data binding](xref:blazor/components/data-binding), [dependency injection](xref:blazor/fundamentals/dependency-injection), and other features of components.
Expand Down
6 changes: 4 additions & 2 deletions aspnetcore/blazor/components/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ uid: blazor/components/lifecycle

This article explains the ASP.NET Core Razor component lifecycle and how to use lifecycle events.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Lifecycle events

The Razor component processes Razor component lifecycle events in a set of synchronous and asynchronous lifecycle methods. The lifecycle methods can be overridden to perform additional operations in components during component initialization and rendering.

This article simplifies component lifecycle event processing in order to clarify complex framework logic. You may need to access the [`ComponentBase` reference source](https://github.com/dotnet/aspnetcore/blob/main/src/Components/Components/src/ComponentBase.cs) to integrate custom event processing with Blazor's lifecycle event processing. Code comments in the reference source include additional remarks on lifecycle event processing that don't appear in this article or in the [API documentation](/dotnet/api/). Blazor's lifecycle event processing has changed over time and is subject to change without notice each release.

[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]

## Lifecycle events

The following simplified diagrams illustrate Razor component lifecycle event processing. The C# methods associated with the lifecycle events are defined with examples in the following sections of this article.

Component lifecycle events:
Expand Down
6 changes: 6 additions & 0 deletions aspnetcore/blazor/components/overwriting-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ uid: blazor/components/overwriting-parameters
---
# Avoid overwriting parameters in ASP.NET Core Blazor

This article explains how to avoid overwriting parameters in Blazor apps during rerendering.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Overwritten parameters

The Blazor framework generally imposes safe parent-to-child parameter assignment:

* Parameters aren't overwritten unexpectedly.
Expand Down
10 changes: 5 additions & 5 deletions aspnetcore/blazor/components/prerender.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ This article explains Razor component prerendering scenarios for server-rendered

*Prerendering* is the process of initially rendering page content on the server without enabling event handlers for rendered controls. The server outputs the HTML UI of the page as soon as possible in response to the initial request, which makes the app feel more responsive to users. Prerendering can also improve [Search Engine Optimization (SEO)](https://developer.mozilla.org/docs/Glossary/SEO) by rendering content for the initial HTTP response that search engines use to calculate page rank.

[!INCLUDE[](~/blazor/includes/location-client-and-server-net8-or-later.md)]

## Persist prerendered state

Without persisting prerendered state, state used during prerendering is lost and must be recreated when the app is fully loaded. If any state is created asynchronously, the UI may flicker as the prerendered UI is replaced when the component is rerendered.

Consider the following `PrerenderedCounter1` counter component. The component sets an initial random counter value during prerendering in [`OnInitialized` lifecycle method](xref:blazor/components/lifecycle#component-initialization-oninitializedasync). After the SignalR connection to the client is established, the component rerenders, and the initial count value is replaced when `OnInitialized` executes a second time.

`Components/Pages/PrerenderedCounter1.razor`:
`PrerenderedCounter1.razor`:

```razor
@page "/prerendered-counter-1"
@rendermode InteractiveServer
@inject ILogger<PrerenderedCounter1> Logger
<PageTitle>Prerendered Counter 1</PageTitle>
Expand Down Expand Up @@ -121,13 +122,12 @@ The following example demonstrates the general pattern:
}
```

The following counter component example persists counter state during prerendering and retrieves the state to initialize the component.
The following counter component example persists counter state during prerendering and retrieves the state to initialize the component.

`Components/Pages/PrerenderedCounter2.razor`:
`PrerenderedCounter2.razor`:

```razor
@page "/prerendered-counter-2"
@rendermode InteractiveServer
@implements IDisposable
@inject ILogger<PrerenderedCounter2> Logger
@inject PersistentComponentState ApplicationState
Expand Down
7 changes: 4 additions & 3 deletions aspnetcore/blazor/components/quickgrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ uid: blazor/components/quickgrid

The `QuickGrid` component is a Razor component for quickly and efficiently displaying data in tabular form. `QuickGrid` provides a simple and convenient data grid component for common grid rendering scenarios and serves as a reference architecture and performance baseline for building data grid components. `QuickGrid` is highly optimized and uses advanced techniques to achieve optimal rendering performance.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Package

Add a package reference for the [`Microsoft.AspNetCore.Components.QuickGrid`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.QuickGrid) package.
Expand Down Expand Up @@ -52,11 +54,12 @@ To implement a `QuickGrid` component:

For example, add the following component to render a grid.

The component assumes that the Interactive Server render mode (`InteractiveServer`) is inherited from a parent component or applied globally to the app, which enables interactive features. For the following example, the only interactive feature is sortable columns.

`QuickGridExample.razor`:

```razor
@page "/quickgrid-example"
@rendermode InteractiveServer
@using Microsoft.AspNetCore.Components.QuickGrid
<QuickGrid Items="@people">
Expand All @@ -80,8 +83,6 @@ For example, add the following component to render a grid.
}
```

The preceding example specifies interactive server-side rendering (interactive SSR) with `@rendermode InteractiveServer`, which enables the `QuickGrid`'s interactive features. In this case, the only interactive feature is sortable columns.

For an example that uses an <xref:System.Linq.IQueryable> with Entity Framework Core as the queryable data source, see the [`SampleQuickGridComponent` component in the ASP.NET Core Basic Test App (`dotnet/aspnetcore` GitHub repository)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/test/testassets/BasicTestApp/QuickGridTest/SampleQuickGridComponent.razor).

[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]
Expand Down
4 changes: 3 additions & 1 deletion aspnetcore/blazor/components/rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ uid: blazor/components/rendering

This article explains Razor component rendering in ASP.NET Core Blazor apps, including when to call <xref:Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged%2A> to manually trigger a component to render.

Components *must* render when they're first added to the component hierarchy by a parent component. This is the only time that a component must render. Components *may* render at other times according to their own logic and conventions.
[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Rendering conventions for `ComponentBase`

Components *must* render when they're first added to the component hierarchy by a parent component. This is the only time that a component must render. Components *may* render at other times according to their own logic and conventions.

By default, Razor components inherit from the <xref:Microsoft.AspNetCore.Components.ComponentBase> base class, which contains logic to trigger rerendering at the following times:

* After applying an updated set of [parameters](xref:blazor/components/data-binding#binding-with-component-parameters) from a parent component.
Expand Down
6 changes: 6 additions & 0 deletions aspnetcore/blazor/components/sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ uid: blazor/components/sections
-->

This article explains how to control the content in a Razor component from a child Razor component.

[!INCLUDE[](~/blazor/includes/location-client-and-server-net8-or-later.md)]

## Blazor sections

To control the content in a Razor component from a child Razor component, Blazor supports *sections* using the following built-in components:

* <xref:Microsoft.AspNetCore.Components.Sections.SectionOutlet>: Renders content provided by <xref:Microsoft.AspNetCore.Components.Sections.SectionContent> components with matching <xref:Microsoft.AspNetCore.Components.Sections.SectionOutlet.SectionName%2A> or <xref:Microsoft.AspNetCore.Components.Sections.SectionOutlet.SectionId%2A> arguments. Two or more <xref:Microsoft.AspNetCore.Components.Sections.SectionOutlet> components can't have the same <xref:Microsoft.AspNetCore.Components.Sections.SectionOutlet.SectionName%2A> or <xref:Microsoft.AspNetCore.Components.Sections.SectionOutlet.SectionId%2A>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ uid: blazor/components/attribute-splatting

Components can capture and render additional attributes in addition to the component's declared parameters. Additional attributes can be captured in a dictionary and then *splatted* onto an element when the component is rendered using the [`@attributes`](xref:mvc/views/razor#attributes) Razor directive attribute. This scenario is useful for defining a component that produces a markup element that supports a variety of customizations. For example, it can be tedious to define attributes separately for an `<input>` that supports many parameters.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Attribute splatting

In the following `Splat` component:
Expand Down
2 changes: 2 additions & 0 deletions aspnetcore/blazor/components/synchronization-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Blazor uses a synchronization context (<xref:System.Threading.SynchronizationCon

Blazor's server-side synchronization context attempts to emulate a single-threaded environment so that it closely matches the WebAssembly model in the browser, which is single threaded. At any given point in time, work is performed on exactly one thread, which yields the impression of a single logical thread. No two operations execute concurrently.

[!INCLUDE[](~/blazor/includes/location-client-and-server-pre-net8.md)]

## Avoid thread-blocking calls

Generally, don't call the following methods in components. The following methods block the execution thread and thus block the app from resuming work until the underlying <xref:System.Threading.Tasks.Task> is complete:
Expand Down
Loading

0 comments on commit dc64c7d

Please sign in to comment.