Skip to content

Allow access to GetDisplayName for components #65108

Open

Description

@mguinness

DisplayNameFor support in Blazor issue was closed in #64636. It provides the new DisplayName component and the internal ExpressionMemberAccessor class enables it to retrieve the display name for a model property:

  1. First checks for DisplayAttribute.Name (System.ComponentModel.DataAnnotations)
  2. Falls back to DisplayNameAttribute.DisplayName (System.ComponentModel)
  3. Uses the property name itself if no attributes are present

However, other components don't have support and will still have the following issues:

  • Hardcode label text (violating DRY principles and making localization difficult)
  • Build custom reflection-based solutions
  • Duplicate display name information across models and views

This is apparent in both the QuickGrid component needing custom code for Display name support and also InputBase using hardcoded Display name support.

In addition, third-party components also have the same problem in libraries like DevExpress, SyncFusion, Telerik etc. that all need to show the display name for UI. The issue MudDataGrid: Support DisplayAttribute for PropertyColumn title demonstrates the need for commonality.

The proposal would mean opening up access to GetDisplayName in the ExpressionMemberAccessor class. It's such a common use case that should be unified within Blazor, instead of separate implementations. Also consider moving namespace to Microsoft.AspNetCore.Components as this functionality isn't restricted to forms.

Activity

  1. added
    area-blazor
    on Jan 17, 2026
  2. javiercn commented on Jan 19, 2026

    @javiercn
    Member

    @mguinness thanks for contacting us.

    The proposal would mean opening up access to GetDisplayName in the ExpressionMemberAccessor class.

    This is what the component is for. Instead of using a PropertyColumn you could use a TemplateColumn and automatically provide the DisplayName component. Other components can use the DisplayName component to render the display name at the right time.

    In general, components are our public interface and extensibility point. We don't expose internal helpers like the one you mention as that precludes from changing things in the future if we need to.

  3. added this to the Backlog milestone on Jan 19, 2026
  4. mguinness commented on Jan 20, 2026

    @mguinness
    Author

    This is what the component is for. Instead of using a PropertyColumn you could use a TemplateColumn and automatically provide the DisplayName component. Other components can use the DisplayName component to render the display name at the right time.

    OK, but that's a lot of extra markup you would need for every column. The existing solution in documentation to subclass PropertyColumn and then use <DisplayNameColumn Property="movie => movie.ReleaseDate" /> is better IMO.

    MudBlazor has an elegant solution using an attribute on the model to automatically assign the form labels shown in Automatically set Labels. This has to be a such a common use case that should be adopted elsewhere by components like QuickGrid.

    Will link this issue in the ASP.NET Core Roadmap for .NET 11 discussion to get feedback from other users regarding this feature.

  5. kgar commented on Nov 13, 2026

    @kgar

    At my job, we're using Blazor across most of our applications, and we have this same need in our codebase. For now, my workaround was to just copy the implementation of ExpressionMemberAccessor from the aspnetcore source code (the parts that could be copied; I skipped the Hot Reload content).

    We have a pretty nontrivial shared component surface area, and we often need to know things about the related form model properties above and beyond just the display name, for which we also use MemberInfo static caching. To express further interest from the user-base, I and my team of 13 think it would be nice to have access to ExpressionMemberAccessor as a feature, as well as some more support for getting other data annotation metadata, leveraging MemberInfo static caching. We're pretty committed to Blazor and would enjoy the QoL / DX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazor

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions