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 917425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:12:34+00:00 2026-05-15T18:12:34+00:00

I’ve putted a Description attribute on my property,but the Description property on the ModelMetada

  • 0

I’ve putted a Description attribute on my property,but the Description property on the ModelMetada is null anyway.

[Description("sss")]
public int Id { get; set; }

BTW Is I've putted corect?

EDIT

I’ve had a look at the MVC source. It doesn’t seem to be a bug. The decsription attribute is just never used. There is a property in the Metadata class but this property is never set or called. The CreateMetadata method has no code to work with the decription attribute.The solution would be to override the create method and also edit the templates.

  • 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-15T18:12:35+00:00Added an answer on May 15, 2026 at 6:12 pm

    While trying to find how to get this working I came across a blog post that said neither Description nor Watermark are usable with the present incarnation of the DataAnnotations framework.

    I came up with a workaround that looks roughly like this:

    (Disclaimer: this code is edited from my compiling version to remove it from a metadata provider built through composition so it may not compile directly without some touchups.)

    public class CustomDataAnnotationsModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
        protected override ModelMetadata CreateMetadata(IEnumerable<System.Attribute> attributes, System.Type containerType, System.Func<object> modelAccessor, System.Type modelType, string propertyName)
        {
            var baseModelMetadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
            var result = new CustomMetadata(modelMetadataProvider, containerType, modelAccessor, modelType, propertyName, attributes.OfType<DisplayColumnAttribute>().FirstOrDefault(), attributes)
            {
                TemplateHint = !string.IsNullOrEmpty(templateName) ?                              templateName : baseModelMetaData.TemplateHint,
                HideSurroundingHtml = baseModelMetaData.HideSurroundingHtml,
                DataTypeName = baseModelMetaData.DataTypeName,
                IsReadOnly = baseModelMetaData.IsReadOnly,
                NullDisplayText = baseModelMetaData.NullDisplayText,
                DisplayFormatString = baseModelMetaData.DisplayFormatString,
                ConvertEmptyStringToNull = baseModelMetaData.ConvertEmptyStringToNull,
                EditFormatString = baseModelMetaData.EditFormatString,
                ShowForDisplay = baseModelMetaData.ShowForDisplay,
                ShowForEdit = baseModelMetaData.ShowForEdit,
                DisplayName = baseModelMetaData.DisplayName
            };
            return result;
        }
    }
    
    public class CustomMetadata : DataAnnotationsModelMetadata
    {
        private string _description;
    
        public CustomMetadata(DataAnnotationsModelMetadataProvider provider, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName, DisplayColumnAttribute displayColumnAttribute, IEnumerable<Attribute> attributes)
                : base(provider, containerType, modelAccessor, modelType, propertyName, displayColumnAttribute)
            {
                var descAttr = attributes.OfType<DescriptionAttribute>().SingleOrDefault();
                        _description = descAttr != null ? descAttr.Description : "";
            }
    
            // here's the really important part
            public override string Description
            {
                get
                {
                    return _description;
                }
                set
                {
                    _description = value;
                }
            }
    }
    

    Then in your Global.asax in Application_Start or wherever you register your model metadata providers:

    ModelMetadataProviders.Current = new CustomMetadataProvider();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.