dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.42k stars 10.01k forks source link

DisplayNameFor support in Blazor #49147

Open danroth27 opened 1 year ago

danroth27 commented 1 year ago

MVC & Razor Pages have the DisplayNameFor HTML helper. Blazor doesn't currently have any helpers for creating a display name for model properties or expressions. This would be useful for scaffolding form field labels based on a model type, where you pick up the display name from attributes, like [Display(Name="Release date")], on the model. QuickGrid has some logic for displaying column headings based on a model type, but it doesn't support the DisplayAttribute.

agriffard commented 1 year ago

An attribute using a Resource key could be also useful to localize it.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

guardrex commented 1 year ago

Side-note on my hitting this, too, while performing doc updates.

I was also going to cover it this way ...

[Required, DisplayName("Production Date")]
public DateTime ProductionDate { get; set; }

Both decorations ([Display] and [DisplayName]) aren't currently functional.

I'm going to place some guidance on those approaches, but I'll comment it out so that it won't appear right now and leave a tracking note in place to keep an 👁️ on the issue.

I can confirm that the DisplayName parameter on InputX components is working ✔️ ...

<InputDate @bind-Value="Model!.ProductionDate" DisplayName="Production Date" />

image

GilShalit commented 1 year ago

I find it strange that decorating class members with attributes and using those attributes in code (so central and useful in Razor pages) has been abasically dropped for Blazor. I would suggest this should be pushed forward if possible.

flatproject commented 8 months ago

It doesnt look like it will make it it in .Net9 since its not in the planning doc, hoping for .Net 10......

guardrex commented 5 months ago

Noting that there are related open issues (and a closed PR) on this subject ...

@danroth27 ... I hit this again for the new tutorial. I think subclassing PropertyColumn is going too far for an introductory tutorial, so I'll just have the dev set the Title of the column in the QuickGrid. However, I have opened an issue for the QuickGrid article to add a section to the article on how to subclass PropertyColumn.