Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:08:47+00:00 2026-05-30T05:08:47+00:00

The DisplayAttribute in System.ComponentModel.DataAnnotations has a GroupName property, which allows you to logically group

  • 0

The DisplayAttribute in System.ComponentModel.DataAnnotations has a GroupName property, which allows you to logically group fields together in a UI control (e.g. a property grid in WPF/WinForms).

I am trying to access this metadata in an ASP.NET MVC3 application, essentially to create a property grid. If my model looks like this:

public class Customer
{
    [ReadOnly]
    public int Id { get;set; }

    [Display(Name = "Name", Description = "Customer's name", GroupName = "Basic")]
    [Required(ErrorMessage = "Please enter the customer's name")]
    [StringLength(255)]
    public string Name { get;set; }

    [Display(Name = "Email", Description = "Customer's primary email address", GroupName = "Basic")]
    [Required]
    [StringLength(255)]
    [DataType(DataType.Email)]
    public string EmailAddress { get;set; }

    [Display(Name = "Last Order", Description = "The date when the customer last placed an order", GroupName = "Status")]
    public DateTime LastOrderPlaced { get;set; }

    [Display(Name = "Locked", Description = "Whether the customer account is locked", GroupName = "Status")]
    public bool IsLocked { get;set; }
}

and my view looks like this:

@model Customer

<div class="edit-customer">
    @foreach (var property in ViewData.ModelMetadata.Properties.Where(p => !p.IsReadOnly).OrderBy(p => p.Order))
    {
        <div class="editor-row">
            @Html.DevExpress().Label(settings =>
                {
                    settings.AssociatedControlName = property.PropertyName;
                    settings.Text = property.DisplayName;
                    settings.ToolTip = property.Description;
                }).GetHtml()
            <span class="editor-field">
                @Html.DevExpress().TextBox(settings =>
                    {
                        settings.Name = property.PropertyName;
                        settings.Properties.NullText = property.Watermark;
                        settings.Width = 200;
                        settings.Properties.ValidationSettings.RequiredField.IsRequired = property.IsRequired;
                        settings.ShowModelErrors = true;
                    }).Bind(ViewData[property.PropertyName]).GetHtml()
            </span>
        </div>
    }
</div>

then the form is laid out very nicely based on the metadata, with labels, tooltips, watermarks etc all pulled out of the model’s metadata; but, I would like to be able to group the items together, for instance in a <fieldset> per group. Does anyone know how to get the GroupName out of the metadata, short of writing an extension method for ModelMetadata?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:08:48+00:00Added an answer on May 30, 2026 at 5:08 am

    GroupName is not parsed by the DataAnnotationsModelMetadataProvider. So there’s no way to get it right off the ModelMetadata object, even with an extension method.

    You could implement your own provider that extends the existing one to add support for GroupName, which Brad Wilson explains in his blog.

    You could also write your own attribute instead of using Display(GroupName = ) and implement the IMetadataAware interface to add the groupname to ModelMetadata.AdditionalValues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use the DataAnnotations.DisplayAttribute.Order property to arrange my fields when using the
I'm building a method to get the DisplayAttribute from System.ComponentModel.DataAnnotations to show on a
Why don't DataAnnotations work on public fields? Example: namespace Models { public class Product
I've noticed that the SL3 Validators automatically uses the properties from DisplayAttribute when creating
I have a database table with the following fields item_key, item_value, display_name, uihint I
I'm currently using this for turning an enum into a radio control, public static
I set values for the Order property of the Display attribute in my model
The DescriptionViewer part of the DataField is used to display the Description property of
Is there a way to get the style: display attribute which would have either
I'm using an ordered list in order to get numbering, which works perfectly fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.