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
|[`Label<TValue>`](#label-component) (.NET 11 or later) |`<label>`|
40
41
41
42
For more information on the <xref:Microsoft.AspNetCore.Components.Forms.InputFile> component, see <xref:blazor/file-uploads>.
42
43
@@ -458,28 +459,93 @@ The validation summary displays the friendly name when the field's value is inva
458
459
459
460
> The Production Date field must be a date.
460
461
461
-
<!-- UPDATE 11.0 The feature has been backlogged.
462
-
https://github.com/dotnet/aspnetcore/issues/49147
462
+
:::moniker-end
463
463
464
-
> [!NOTE]
465
-
> Alternatively, the [`[Display]` attribute](xref:System.ComponentModel.DataAnnotations.DisplayAttribute) on the model class property is supported:
466
-
>
467
-
> ```csharp
468
-
> [Required, Display(Name = "Production Date")]
469
-
> public DateTime ProductionDate { get; set; }
470
-
> ```
471
-
>
472
-
> [`[DisplayName]` attribute](xref:System.ComponentModel.DisplayNameAttribute) is also supported:
473
-
>
474
-
> ```csharp
475
-
> [Required, DisplayName("Production Date")]
476
-
> public DateTime ProductionDate { get; set; }
477
-
> ```
478
-
>
479
-
> Between the two approaches, the `[Display]` attribute is recommended, which makes additional properties available. The `[Display]` attribute also enables assigning a resource type for localization.
The `DisplayName` component can be used to display property names from metadata attributes
471
+
472
+
```csharp
473
+
[Required, DisplayName("Production Date")]
474
+
publicDateTimeProductionDate { get; set; }
475
+
```
476
+
477
+
The [`[Display]` attribute](xref:System.ComponentModel.DataAnnotations.DisplayAttribute) on the model class property is supported:
478
+
479
+
```csharp
480
+
[Required, Display(Name="Production Date")]
481
+
publicDateTimeProductionDate { get; set; }
482
+
```
483
+
484
+
Between the two approaches, the `[Display]` attribute is recommended, which makes additional properties available. The `[Display]` attribute also enables assigning a resource type for localization. When both attributes are present, `[Display]` takes precedence over `[DisplayName]`. If neither attribute is present, the component falls back to the property name.
485
+
486
+
Use the `DisplayName` component in labels or table headers:
The `Label` component renders a `<label>` element that automatically extracts the display name from a model property using `[Display]` or `[DisplayName]` attributes. This simplifies form creation by eliminating the need to manually specify label text.
507
+
508
+
### Nested pattern
509
+
510
+
The nested pattern wraps the input component inside the label:
0 commit comments