You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/forms/binding.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ Assignment to <xref:Microsoft.AspNetCore.Components.Forms.EditForm.Model?display
31
31
32
32
@code {
33
33
[SupplyParameterFromForm]
34
-
public Starship? Model { get; set; }
34
+
private Starship? Model { get; set; }
35
35
36
36
protected override void OnInitialized() => Model ??= new();
37
37
}
@@ -73,7 +73,7 @@ Assignment to <xref:Microsoft.AspNetCore.Components.Forms.EditForm.EditContext?d
73
73
private EditContext? editContext;
74
74
75
75
[SupplyParameterFromForm]
76
-
public Starship? Model { get; set; }
76
+
private Starship? Model { get; set; }
77
77
78
78
protected override void OnInitialized()
79
79
{
@@ -184,7 +184,7 @@ In the following example, the `HelloFormFromLibrary` component has a form named
184
184
bool submitted = false;
185
185
186
186
[SupplyParameterFromForm]
187
-
public string? Name { get; set; }
187
+
private string? Name { get; set; }
188
188
189
189
private void Submit() => submitted = true;
190
190
}
@@ -219,15 +219,15 @@ The following `NamedFormsWithScope` component uses the library's `HelloFormFromL
219
219
bool submitted = false;
220
220
221
221
[SupplyParameterFromForm]
222
-
public string? Name { get; set; }
222
+
private string? Name { get; set; }
223
223
224
224
private void Submit() => submitted = true;
225
225
}
226
226
```
227
227
228
228
## Supply a parameter from the form (`[SupplyParameterFromForm]`)
229
229
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`.
231
231
232
232
You can specify the following form binding parameters to the [`[SupplyParameterFromForm]` attribute](xref:Microsoft.AspNetCore.Components.SupplyParameterFromFormAttribute):
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`.
0 commit comments