From 594f7bcd5cc671dc0ea6fb3dd57cf19c6c5ff901 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Thu, 4 Dec 2025 14:28:56 +0100 Subject: [PATCH 1/6] Proposal of `DisplayNameFor`. --- aspnetcore/blazor/forms/input-components.md | 45 ++++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/aspnetcore/blazor/forms/input-components.md b/aspnetcore/blazor/forms/input-components.md index 8dcc271dc3d3..ac3ca69c6257 100644 --- a/aspnetcore/blazor/forms/input-components.md +++ b/aspnetcore/blazor/forms/input-components.md @@ -458,27 +458,34 @@ The validation summary displays the friendly name when the field's value is inva > The Production Date field must be a date. - +The component can be used to display property names from metadata attributes. The [`[Display]` attribute](xref:System.ComponentModel.DataAnnotations.DisplayAttribute) on the model class property is supported: + +```csharp +[Required, Display(Name = "Production Date")] +public DateTime ProductionDate { get; set; } +``` + +[`[DisplayName]` attribute](xref:System.ComponentModel.DisplayNameAttribute) is also supported: + +```csharp +[Required, DisplayName("Production Date")] +public DateTime ProductionDate { get; set; } +``` + +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 itself. + +Use the `DisplayName` component in labels or table headers: + +```razor + +``` :::moniker-end From fc9e38d818bd49d040623753ee1d7f413a4d6eb2 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 5 Dec 2025 12:19:57 +0100 Subject: [PATCH 2/6] Update aspnetcore/blazor/forms/input-components.md Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com> --- aspnetcore/blazor/forms/input-components.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/forms/input-components.md b/aspnetcore/blazor/forms/input-components.md index ac3ca69c6257..04aeae6701cc 100644 --- a/aspnetcore/blazor/forms/input-components.md +++ b/aspnetcore/blazor/forms/input-components.md @@ -469,7 +469,7 @@ The component can b public DateTime ProductionDate { get; set; } ``` -[`[DisplayName]` attribute](xref:System.ComponentModel.DisplayNameAttribute) is also supported: +The [`[DisplayName]` attribute](xref:System.ComponentModel.DisplayNameAttribute) is also supported: ```csharp [Required, DisplayName("Production Date")] From fa9a4ee5467cab82cf0a25ef5d994f39852db695 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 5 Dec 2025 12:20:05 +0100 Subject: [PATCH 3/6] Update aspnetcore/blazor/forms/input-components.md Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com> --- aspnetcore/blazor/forms/input-components.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/forms/input-components.md b/aspnetcore/blazor/forms/input-components.md index 04aeae6701cc..bc3bfb41628b 100644 --- a/aspnetcore/blazor/forms/input-components.md +++ b/aspnetcore/blazor/forms/input-components.md @@ -476,7 +476,7 @@ The [`[DisplayName]` attribute](xref:System.ComponentModel.DisplayNameAttribute) public DateTime ProductionDate { get; set; } ``` -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 itself. +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. Use the `DisplayName` component in labels or table headers: From 2ba526f0d73efe5ddb49a598362596c74a607a3b Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 5 Dec 2025 13:05:00 +0100 Subject: [PATCH 4/6] Fix order. --- aspnetcore/blazor/forms/input-components.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aspnetcore/blazor/forms/input-components.md b/aspnetcore/blazor/forms/input-components.md index bc3bfb41628b..92ca564cd69f 100644 --- a/aspnetcore/blazor/forms/input-components.md +++ b/aspnetcore/blazor/forms/input-components.md @@ -462,17 +462,17 @@ The validation summary displays the friendly name when the field's value is inva :::moniker range=">= aspnetcore-11.0" -The component can be used to display property names from metadata attributes. The [`[Display]` attribute](xref:System.ComponentModel.DataAnnotations.DisplayAttribute) on the model class property is supported: +The component can be used to display property names from metadata attributes. ```csharp -[Required, Display(Name = "Production Date")] +[Required, DisplayName("Production Date")] public DateTime ProductionDate { get; set; } ``` -The [`[DisplayName]` attribute](xref:System.ComponentModel.DisplayNameAttribute) is also supported: +The [`[Display]` attribute](xref:System.ComponentModel.DataAnnotations.DisplayAttribute) on the model class property is supported: ```csharp -[Required, DisplayName("Production Date")] +[Required, Display(Name = "Production Date")] public DateTime ProductionDate { get; set; } ``` From 908c71ffdf2b96e85562ca925dd2ae4e06085e6d Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 5 Dec 2025 13:26:59 +0100 Subject: [PATCH 5/6] Update aspnetcore/blazor/forms/input-components.md Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com> --- aspnetcore/blazor/forms/input-components.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/forms/input-components.md b/aspnetcore/blazor/forms/input-components.md index 92ca564cd69f..33255ad30a12 100644 --- a/aspnetcore/blazor/forms/input-components.md +++ b/aspnetcore/blazor/forms/input-components.md @@ -462,7 +462,7 @@ The validation summary displays the friendly name when the field's value is inva :::moniker range=">= aspnetcore-11.0" -The component can be used to display property names from metadata attributes. +The component can be used to display property names from metadata attributes: ```csharp [Required, DisplayName("Production Date")] From f9a127c5cc179bfa26546e417781c17d8d3a48d6 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 5 Dec 2025 13:46:45 +0100 Subject: [PATCH 6/6] Update aspnetcore/blazor/forms/input-components.md Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com> --- aspnetcore/blazor/forms/input-components.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aspnetcore/blazor/forms/input-components.md b/aspnetcore/blazor/forms/input-components.md index 33255ad30a12..4f2320b95a2f 100644 --- a/aspnetcore/blazor/forms/input-components.md +++ b/aspnetcore/blazor/forms/input-components.md @@ -462,7 +462,11 @@ The validation summary displays the friendly name when the field's value is inva :::moniker range=">= aspnetcore-11.0" -The component can be used to display property names from metadata attributes: + +The `DisplayName` component can be used to display property names from metadata attributes ```csharp [Required, DisplayName("Production Date")]