Skip to content

Commit ce61676

Browse files
authored
Make [SupplyParameterFrom{X}] props private (#33443)
1 parent 217c7ec commit ce61676

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

aspnetcore/blazor/advanced-scenarios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to incorporate manual logic for building Blazor render tr
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 02/09/2024
8+
ms.date: 08/26/2024
99
uid: blazor/advanced-scenarios
1010
---
1111
# ASP.NET Core Blazor advanced scenarios (render tree construction)

aspnetcore/blazor/components/class-libraries-and-static-server-side-rendering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Consider the following example:
108108
109109
@code {
110110
[SupplyParameterFromForm]
111-
public Product? Model { get; set; }
111+
private Product? Model { get; set; }
112112
113113
protected override void OnInitialized() => Model ??= new();
114114

aspnetcore/blazor/components/render-modes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Components use these properties to render content depending on their location or
246246
private bool disabled = true;
247247
248248
[SupplyParameterFromForm]
249-
public Movie? Movie { get; set; }
249+
private Movie? Movie { get; set; }
250250
251251
protected override async Task OnInitializedAsync()
252252
{

aspnetcore/blazor/forms/binding.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Assignment to <xref:Microsoft.AspNetCore.Components.Forms.EditForm.Model?display
3131
3232
@code {
3333
[SupplyParameterFromForm]
34-
public Starship? Model { get; set; }
34+
private Starship? Model { get; set; }
3535
3636
protected override void OnInitialized() => Model ??= new();
3737
}
@@ -73,7 +73,7 @@ Assignment to <xref:Microsoft.AspNetCore.Components.Forms.EditForm.EditContext?d
7373
private EditContext? editContext;
7474
7575
[SupplyParameterFromForm]
76-
public Starship? Model { get; set; }
76+
private Starship? Model { get; set; }
7777
7878
protected override void OnInitialized()
7979
{
@@ -184,7 +184,7 @@ In the following example, the `HelloFormFromLibrary` component has a form named
184184
bool submitted = false;
185185
186186
[SupplyParameterFromForm]
187-
public string? Name { get; set; }
187+
private string? Name { get; set; }
188188
189189
private void Submit() => submitted = true;
190190
}
@@ -219,15 +219,15 @@ The following `NamedFormsWithScope` component uses the library's `HelloFormFromL
219219
bool submitted = false;
220220
221221
[SupplyParameterFromForm]
222-
public string? Name { get; set; }
222+
private string? Name { get; set; }
223223
224224
private void Submit() => submitted = true;
225225
}
226226
```
227227

228228
## Supply a parameter from the form (`[SupplyParameterFromForm]`)
229229

230-
The `[SupplyParameterFromForm]` attribute indicates that the value of the associated property should be supplied from the form data for the form. Data in the request that matches the name of the property is bound to the property. Inputs based on `InputBase<TValue>` generate form value names that match the names Blazor uses for model binding.
230+
The `[SupplyParameterFromForm]` attribute indicates that the value of the associated property should be supplied from the form data for the form. Data in the request that matches the name of the property is bound to the property. Inputs based on `InputBase<TValue>` generate form value names that match the names Blazor uses for model binding. Unlike component parameter properties (`[Parameter]`), properties annotated with `[SupplyParameterFromForm]` aren't required to be marked `public`.
231231

232232
You can specify the following form binding parameters to the [`[SupplyParameterFromForm]` attribute](xref:Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute):
233233

aspnetcore/blazor/forms/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to use forms in Blazor.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 02/09/2024
8+
ms.date: 08/26/2024
99
uid: blazor/forms/index
1010
---
1111
# ASP.NET Core Blazor forms overview

aspnetcore/blazor/forms/input-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn about built-in Blazor input components.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 02/09/2024
8+
ms.date: 08/26/2024
99
uid: blazor/forms/input-components
1010
---
1111
# ASP.NET Core Blazor input components

aspnetcore/blazor/forms/validation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to use validation in Blazor forms.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 02/09/2024
8+
ms.date: 08/26/2024
99
uid: blazor/forms/validation
1010
---
1111
# ASP.NET Core Blazor forms validation
@@ -606,7 +606,7 @@ In the following component, update the namespace of the **`Shared`** project (`@
606606
private string messageStyles = "visibility:hidden";
607607
608608
[SupplyParameterFromForm]
609-
public Starship? Model { get; set; }
609+
private Starship? Model { get; set; }
610610
611611
protected override void OnInitialized() =>
612612
Model ??= new() { ProductionDate = DateTime.UtcNow };

aspnetcore/blazor/fundamentals/routing.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,15 +856,19 @@ Specify the `[SupplyParameterFromQuery]` attribute's <xref:Microsoft.AspNetCore.
856856

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

859+
Unlike component parameter properties (`[Parameter]`), `[SupplyParameterFromQuery]` properties can be marked `private` in addition to `public`.
860+
859861
```csharp
860862
[SupplyParameterFromQuery(Name = "{QUERY PARAMETER NAME}")]
861-
public string? {COMPONENT PARAMETER NAME} { get; set; }
863+
private string? {COMPONENT PARAMETER NAME} { get; set; }
862864
```
863865

864866
:::moniker-end
865867

866868
:::moniker range=">= aspnetcore-6.0 < aspnetcore-8.0"
867869

870+
Just like component parameter properties (`[Parameter]`), `[SupplyParameterFromQuery]` properties are always `public` properties in .NET 6/7. In .NET 8 or later, `[SupplyParameterFromQuery]` properties can be marked `public` or `private`.
871+
868872
```csharp
869873
[Parameter]
870874
[SupplyParameterFromQuery(Name = "{QUERY PARAMETER NAME}")]
@@ -913,13 +917,13 @@ In the following example with a URL of `/search?filter=scifi%20stars&page=3&star
913917
914918
@code {
915919
[SupplyParameterFromQuery]
916-
public string? Filter { get; set; }
920+
private string? Filter { get; set; }
917921
918922
[SupplyParameterFromQuery]
919-
public int? Page { get; set; }
923+
private int? Page { get; set; }
920924
921925
[SupplyParameterFromQuery(Name = "star")]
922-
public string[]? Stars { get; set; }
926+
private string[]? Stars { get; set; }
923927
}
924928
```
925929

0 commit comments

Comments
 (0)