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 am using ASP.NET MVC 3.0 and KnockoutJS . I was trying to add
I am using ASP.NET 4 and MVC and trying to add code to handle
Using Asp.Net MVC 3 (Razor). I'm trying to add the blockUI plug in to
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from
When using ASP.NET MVC plus Entity Framework, and trying to implement a generic repository
I'm trying to write some code using pure SQL using ASP.NET MVC. I assume
I am trying to create a drop down list using asp.net mvc. Model: public
I am using ASP.Net 4.0 MVC to query active directory. I am trying to
I am using JW Player in an ASP.NET MVC application and I'm trying to
I am trying to use NServiceBus with an ASP.NET MVC 2 website (using VS

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.