Skip to content
Merged
2 changes: 1 addition & 1 deletion aspnetcore/blazor/components/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ In `Pages/_Host.cshtml` of Blazor apps that are `ServerPrerendered` in a Blazor

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

Decide what state to persist using the <xref:Microsoft.AspNetCore.Components.PersistentComponentState> service. The [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) applied to a property registers a callback to persist the state during prerendering and loads it when the component renders interactively or the service is instantiated.
Decide what state to persist using the <xref:Microsoft.AspNetCore.Components.PersistentComponentState> service. The [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) applied to a `public` property registers a callback to persist the state during prerendering and loads it when the component renders interactively or the service is instantiated.

In the following example, the `{TYPE}` placeholder represents the type of data to persist (for example, `WeatherForecast[]`).

Expand Down
4 changes: 2 additions & 2 deletions aspnetcore/blazor/forms/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Standard HTML forms are supported. Create a form using the normal HTML `<form>`
In the preceding `StarshipPlainForm` component:

* The form is rendered where the `<form>` element appears. The form is named with the [`@formname`](xref:mvc/views/razor#formname) directive attribute, which uniquely identifies the form to the Blazor framework.
* The model is created in the component's `@code` block and held in a public property (`Model`). The `[SupplyParameterFromForm]` attribute indicates that the value of the associated property should be supplied from the form data. Data in the request that matches the property's name is bound to the property.
* The model is created in the component's `@code` block and held in a `public` property (`Model`). The `[SupplyParameterFromForm]` attribute indicates that the value of the associated property should be supplied from the form data. Data in the request that matches the property's name is bound to the property.
* The <xref:Microsoft.AspNetCore.Components.Forms.InputText> component is an input component for editing string values. The `@bind-Value` directive attribute binds the `Model.Id` model property to the <xref:Microsoft.AspNetCore.Components.Forms.InputText> component's <xref:Microsoft.AspNetCore.Components.Forms.InputBase%601.Value%2A> property.
* The `Submit` method is registered as a handler for the <!-- <xref:Microsoft.AspNetCore.Components.Forms.EditForm.OnSubmit> --> `@onsubmit` callback. The handler is called when the form is submitted by the user.

Expand Down Expand Up @@ -117,7 +117,7 @@ A form is defined using the Blazor framework's <xref:Microsoft.AspNetCore.Compon
In the preceding `Starship1` component:

* The <xref:Microsoft.AspNetCore.Components.Forms.EditForm> component is rendered where the `<EditForm>` element appears. The form is named with the <xref:Microsoft.AspNetCore.Components.Forms.EditForm.FormName> property, which uniquely identifies the form to the Blazor framework.
* The model is created in the component's `@code` block and held in a public property (`Model`). The property is assigned to the <xref:Microsoft.AspNetCore.Components.Forms.EditForm.Model?displayProperty=nameWithType> parameter. The `[SupplyParameterFromForm]` attribute indicates that the value of the associated property should be supplied from the form data. Data in the request that matches the property's name is bound to the property.
* The model is created in the component's `@code` block and held in a `public` property (`Model`). The property is assigned to the <xref:Microsoft.AspNetCore.Components.Forms.EditForm.Model?displayProperty=nameWithType> parameter. The `[SupplyParameterFromForm]` attribute indicates that the value of the associated property should be supplied from the form data. Data in the request that matches the property's name is bound to the property.
* The <xref:Microsoft.AspNetCore.Components.Forms.InputText> component is an [input component](xref:blazor/forms/input-components) for editing string values. The `@bind-Value` directive attribute binds the `Model.Id` model property to the <xref:Microsoft.AspNetCore.Components.Forms.InputText> component's <xref:Microsoft.AspNetCore.Components.Forms.InputBase%601.Value%2A> property.
* The `Submit` method is registered as a handler for the <xref:Microsoft.AspNetCore.Components.Forms.EditForm.OnSubmit> callback. The handler is called when the form is submitted by the user.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ The persisted prerendered state is transferred to the client, where it's used to

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

To preserve prerendered state, use the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) to persist state in properties. Properties with this attribute are automatically persisted using the <xref:Microsoft.AspNetCore.Components.PersistentComponentState> service during prerendering. The state is retrieved when the component renders interactively or the service is instantiated.
To persist prerendered state using the <xref:Microsoft.AspNetCore.Components.PersistentComponentState> service, apply the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) to `public` properties. The state is retrieved when the component renders interactively or the <xref:Microsoft.AspNetCore.Components.PersistentComponentState> service is instantiated.

Use `public` properties because reflection is used by the framework for tasks such as [trimming unused code](xref:blazor/performance/app-download-size#intermediate-language-il-trimming) and [source generation](/dotnet/csharp/roslyn-sdk/source-generators-overview).

By default, properties are serialized using the <xref:System.Text.Json?displayProperty=fullName> serializer with default settings and persisted in the prerendered HTML. Serialization isn't trimmer safe and requires preservation of the types used. For more information, see <xref:blazor/host-and-deploy/configure-trimmer>.

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

* The [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) is applied to the nullable `int` type (`CurrentCount`).
* The [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) is applied to the public nullable `CurrentCount` property of type `int?`.
* The counter's state is assigned when `null` in `OnInitialized` and restored automatically when the component renders interactively.

`PrerenderedCounter2.razor`:
Expand Down Expand Up @@ -94,7 +96,7 @@ When the component executes, `CurrentCount` is only set once during prerendering

In the following example that serializes state for multiple components of the same type:

* Properties annotated with the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) are serialized during prerendering.
* Public properties annotated with the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) are serialized during prerendering.
* The [`@key` directive attribute](xref:blazor/components/key#use-of-the-key-directive-attribute) is used to ensure that the state is correctly associated with the component instance.
* The `Element` property is initialized in the [`OnInitialized` lifecycle method](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) to avoid null reference exceptions, similarly to how null references are avoided for query parameters and form data.

Expand Down Expand Up @@ -159,7 +161,7 @@ Serialized properties are identified from the actual service instance:
* Supports shared code in different assemblies.
* Results in each instance exposing the same properties.

The following counter service, `CounterTracker`, marks its current count property, `CurrentCount` with the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute). The property is serialized during prerendering and deserialized when the app becomes interactive wherever the service is injected.
The following counter service, `CounterTracker`, marks its current count property, `CurrentCount` with the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute). The public property is serialized during prerendering and deserialized when the app becomes interactive wherever the service is injected.

`CounterTracker.cs`:

Expand Down
8 changes: 6 additions & 2 deletions aspnetcore/blazor/state-management/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Persisting component state across circuits is built on top of the existing <xref
> [NOTE]
> Persisting component state for prerendering works for any interactive render mode, but circuit state persistence only works for the **Interactive Server** render mode.

Annotate component properties with the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) to enable circuit state persistence. The following example also keys the items with the [`@key` directive attribute](xref:blazor/components/key) to provide a unique identifier for each component instance:
Annotate component `public` properties with the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute) to enable circuit state persistence. The following example also keys the items with the [`@key` directive attribute](xref:blazor/components/key) to provide a unique identifier for each component instance:

```razor
Comment thread
guardrex marked this conversation as resolved.
@foreach (var item in Items)
Expand All @@ -119,7 +119,11 @@ Annotate component properties with the [`[PersistentState]` attribute](xref:Micr
}
```

To persist state for scoped services, annotate service properties with the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute), add the service to the service collection, and call the <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsRazorComponentBuilderExtensions.RegisterPersistentService%2A> extension method with the service:
To persist state for a scoped service:

* Annotate the `public` service property with the [`[PersistentState]` attribute](xref:Microsoft.AspNetCore.Components.PersistentStateAttribute).
* Add the service to the service collection.
* Call the <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsRazorComponentBuilderExtensions.RegisterPersistentService%2A> extension method with the service.
Comment thread
guardrex marked this conversation as resolved.

```csharp
public class CustomUserService
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/blazor/tutorials/movie-database-app/part-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This part of the tutorial series explains how metadata of the `Movie` model is u

## Validation using data annotations

Validation rules are specified on a model class using *data annotations*. The following list shows some of the <xref:System.ComponentModel.DataAnnotations> attributes for user input validation of public properties in a form's model:
Validation rules are specified on a model class using *data annotations*. The following list shows some of the <xref:System.ComponentModel.DataAnnotations> attributes for user input validation of `public` properties in a form's model:

* [`[Required]`](xref:System.ComponentModel.DataAnnotations.RequiredAttribute): Require that the user provide a value.
* [`[StringLength]`](xref:System.ComponentModel.DataAnnotations.StringLengthAttribute): Specifies the minimum and maximum length of characters. Note that a `MinimumLength` passed to the attribute doesn't make the string required (apply the [`[Required]` attribute](xref:System.ComponentModel.DataAnnotations.RequiredAttribute)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This diagnostic is emitted by the [Request Delegate Generator](/aspnet/core/fund

### Rule description

Types that are used for surrogate binding via the [`[AsParameters]`](xref:Microsoft.AspNetCore.Http.AsParametersAttribute) attribute must contain a public parameterized constructor where all parameters to the constructor match the public properties declared on the type. The `TodoRequest` type produces this diagnostic because there is no matching constructor parameter for the `Todo` property.
Types that are used for surrogate binding via the [`[AsParameters]`](xref:Microsoft.AspNetCore.Http.AsParametersAttribute) attribute must contain a `public` parameterized constructor where all parameters to the constructor match the `public` properties declared on the type. The `TodoRequest` type produces this diagnostic because there is no matching constructor parameter for the `Todo` property.

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg6/Program.cs" id="snippet_1" highlight="14,18-22":::

Expand Down
6 changes: 3 additions & 3 deletions aspnetcore/fundamentals/http-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ A typed client accepts an `HttpClient` parameter in its constructor:
In the preceding code:

* The configuration is moved into the typed client.
* The `HttpClient` object is exposed as a public property.
* The `HttpClient` object is exposed as a `public` property.

<!--
The preceding code can be written as:
Expand Down Expand Up @@ -894,7 +894,7 @@ A typed client accepts an `HttpClient` parameter in its constructor:
In the preceding code:

* The configuration is moved into the typed client.
* The `HttpClient` object is exposed as a public property.
* The `HttpClient` object is exposed as a `public` property.

API-specific methods can be created that expose `HttpClient` functionality. For example, the `GetAspNetDocsIssues` method encapsulates code to retrieve open issues.

Expand Down Expand Up @@ -1299,7 +1299,7 @@ A typed client accepts an `HttpClient` parameter in its constructor:

:::code language="csharp" source="http-requests/samples/2.x/HttpClientFactorySample/GitHub/GitHubService.cs" id="snippet1" highlight="5":::

In the preceding code, the configuration is moved into the typed client. The `HttpClient` object is exposed as a public property. It's possible to define API-specific methods that expose `HttpClient` functionality. The `GetAspNetDocsIssues` method encapsulates the code needed to query for and parse out the latest open issues from a GitHub repository.
In the preceding code, the configuration is moved into the typed client. The `HttpClient` object is exposed as a `public` property. It's possible to define API-specific methods that expose `HttpClient` functionality. The `GetAspNetDocsIssues` method encapsulates the code needed to query for and parse out the latest open issues from a GitHub repository.

To register a typed client, the generic <xref:Microsoft.Extensions.DependencyInjection.HttpClientFactoryServiceCollectionExtensions.AddHttpClient%2A> extension method can be used within `Startup.ConfigureServices`, specifying the typed client class:

Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/fundamentals/openapi/include-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public IActionResult PrivateEndpoint() {

C# classes or records used in request or response bodies are represented as schemas
in the generated OpenAPI document.
By default, only public properties are represented in the schema, but there are
By default, only `public` properties are represented in the schema, but there are
<xref:System.Text.Json.JsonSerializerOptions> to also create schema properties for fields.

When the <xref:System.Text.Json.JsonSerializerOptions.PropertyNamingPolicy> is set to camel-case (this is the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public IActionResult PrivateEndpoint() {

C# classes or records used in request or response bodies are represented as schemas
in the generated OpenAPI document.
By default, only public properties are represented in the schema, but there are
By default, only `public` properties are represented in the schema, but there are
<xref:System.Text.Json.JsonSerializerOptions> to also create schema properties for fields.

When the <xref:System.Text.Json.JsonSerializerOptions.PropertyNamingPolicy> is set to camel-case (this is the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public IActionResult PrivateEndpoint() {

C# classes or records used in request or response bodies are represented as schemas
in the generated OpenAPI document.
By default, only public properties are represented in the schema, but there are
By default, only `public` properties are represented in the schema, but there are
<xref:System.Text.Json.JsonSerializerOptions> to also create schema properties for fields.

When the <xref:System.Text.Json.JsonSerializerOptions.PropertyNamingPolicy> is set to camel-case (this is the default
Expand Down
10 changes: 5 additions & 5 deletions aspnetcore/mvc/models/model-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This article explains what model binding is, how it works, and how to customize
Controllers and Razor pages work with data that comes from HTTP requests. For example, route data may provide a record key, and posted form fields may provide values for the properties of the model. Writing code to retrieve each of these values and convert them from strings to .NET types would be tedious and error-prone. Model binding automates this process. The model binding system:

* Retrieves data from various sources such as route data, form fields, and query strings.
* Provides the data to controllers and Razor pages in method parameters and public properties.
* Provides the data to controllers and Razor pages in method parameters and `public` properties.
* Converts string data to .NET types.
* Updates properties of complex types.

Expand Down Expand Up @@ -57,17 +57,17 @@ Model binding tries to find values for the following kinds of targets:

* Parameters of the controller action method that a request is routed to.
* Parameters of the Razor Pages handler method that a request is routed to.
* Public properties of a controller or `PageModel` class, if specified by attributes.
* Public (`public`) properties of a controller or `PageModel` class, if specified by attributes.

### [BindProperty] attribute

Can be applied to a public property of a controller or `PageModel` class to cause model binding to target that property:
Can be applied to a `public` property of a controller or `PageModel` class to cause model binding to target that property:

:::code language="csharp" source="~/mvc/models/model-binding/samples/6.x/ModelBindingSample/Snippets/Pages/Edit.cshtml.cs" id="snippet_Class" highlight="3":::

### [BindProperties] attribute

Can be applied to a controller or `PageModel` class to tell model binding to target all public properties of the class:
Can be applied to a controller or `PageModel` class to tell model binding to target all `public` properties of the class:

:::code language="csharp" source="~/mvc/models/model-binding/samples/6.x/ModelBindingSample/Snippets/Pages/Create.cshtml.cs" id="snippet_Class" highlight="1":::

Expand Down Expand Up @@ -272,7 +272,7 @@ For each property of the complex type, [model binding looks through the sources

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

For binding to a parameter, the prefix is the parameter name. For binding to a `PageModel` public property, the prefix is the public property name. Some attributes have a `Prefix` property that lets you override the default usage of parameter or property name.
For binding to a parameter, the prefix is the parameter name. For binding to a `PageModel` `public` property, the prefix is the property name. Some attributes have a `Prefix` property that lets you override the default usage of parameter or property name.

For example, suppose the complex type is the following `Instructor` class:

Expand Down
Loading
Loading