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

  • Home
  • SEARCH
  • 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 3321198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:02:02+00:00 2026-05-17T23:02:02+00:00

I am using Asp.Net MVC 2, and trying to iterate through the metadata to

  • 0

I am using Asp.Net MVC 2, and trying to iterate through the metadata to add input controls to grid columns. Most attributes like DisplayAttribute, StringLength attribute, etc are not populated by the default modelmetadata provider.

1- I think these attributes are going to be supported in MVC3, right?

2- Is there a custom provider that I can use till MVC3 is out, I remember seeing a custom metadata provider (thought it was in MVCContrib) but could not find it there, anyone knows where to find the metadataprovider supporting this attributes?

  • 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-17T23:02:03+00:00Added an answer on May 17, 2026 at 11:02 pm

    I wrote a provider to handle more attributes than the standard provider does. Here’s the idea:

    /// <summary>
    /// Adds support for data annotation attributes omitted from DataAnnotationsModelMetadataProvider
    /// </summary>
    public class ExtendedDataAnnotationsModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
        protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
        {
            var result = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
    
            DisplayAttribute da = attributes.OfType<DisplayAttribute>().FirstOrDefault();
            if (da != null)
            {
                var autoGenerate = da.GetAutoGenerateFilter();
                if (autoGenerate.HasValue)
                {
                    result.AdditionalValues[AdditionalValuesKeys.AutoGenerateFilter] = autoGenerate.Value;
                }
                var groupName = da.GroupName;
                if (!string.IsNullOrEmpty(groupName))
                {
                    result.AdditionalValues[AdditionalValuesKeys.GroupName] = groupName;
                }
                if (!string.IsNullOrEmpty(da.Prompt))
                {
                    result.Watermark = da.Prompt;
                }
            }
    
            DisplayColumnAttribute dc = attributes.OfType<DisplayColumnAttribute>().FirstOrDefault();
            if (dc != null)
            {
                var sc = dc.SortColumn;
                if (!string.IsNullOrEmpty(sc))
                {
                    result.AdditionalValues[AdditionalValuesKeys.SortColumnName] = sc;
                    if (dc.SortDescending)
                    {
                        result.AdditionalValues[AdditionalValuesKeys.SortDescending] = true;
                    }
                }
            }
    
            StringLengthAttribute sla = attributes.OfType<StringLengthAttribute>().FirstOrDefault();
            if (sla != null)
            {
                result.AdditionalValues[AdditionalValuesKeys.MaximumStringLength] = sla.MaximumLength;
            }
    
            return result;
        }
    }
    

    Naturally, the default templates with MVC don’t actually do anything with that info. You have to customize them yourself.

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

Sidebar

Related Questions

I'm using ASP.NET MVC Framwork and trying to grok the ASP Membership 3.5 stuff.
I am trying to publish an Asp.net MVC web application locally using the NAnt
If you are using ASP.NET MVC how are you doing grid display? Rolled your
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from
This is NOT a Master/Detail question. I am using ASP.Net MVC and trying to
I'm using ASP.NET MVC RC1 and trying to bind a textbox to an object
I am using asp.net mvc and I am trying to send 2 sets of
I'm using ASP.NET MVC 2.0 and I am trying to take advantage of the
I am using ASP.NET MVC 1.1 with Windows authentication. I trying to only authorize
I'm working on an application using ASP.NET MVC 1.0 and I'm trying to inject

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.