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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:53:08+00:00 2026-06-12T09:53:08+00:00

i want to provide a method of changing the labels associated with controls which

  • 0

i want to provide a method of changing the labels associated with controls which will be rendered on the page via a lookup to a sql table.

Ideally i want to inject the meta data display field which is then rendered on the page using the helper.

@Html.LabelFor(m => m.city)

Since this would need to be a sql lookup at runtime, i cannot just change the class scaffolding tt template to stamp on a displayname annotation at design time.

I thought of 3 potential methods.

  1. rewrite all the html.helpers i want to use. Problem with this is you would need to replicate all the functionality of the existing helper prior to making the changes.

  2. write a custom data annotation and stamp it on each property in the class i.e.

    [MyCustomNameAttribute]
    public string city{ get; set; }

    then hopefully in the MyCustomNameAttribute class i can find both the linq field i am referring to, a reference to the metadatamodel and a database context using these i can retrieve and replace the DisplayName based on potential name customisations configured by the User. I tried to do this but was unable to find out how the [Display(Name=”city”)] annotation works in the background.

  3. Modify the entity model backing code to inject the name into the metadatamodel.

Does anyone have any experience of the above?

Cheers
Tim

  • 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-06-12T09:53:09+00:00Added an answer on June 12, 2026 at 9:53 am

    You have to create a custom ModelMetaDataProvider by extending the DataAnnotationsModelMetadataProvider.

    public class CustomModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
        protected override ModelMetadata CreateMetadata(
            IEnumerable<Attribute> attributes,
            Type containerType,
            Func<object> modelAccessor,
            Type modelType,
            string propertyName)
        {
            var meta = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
    
                   if(meta.DisplayName == null)
                   {
                     // TO DO read the display value from database and assign here
                     meta.DisplayName = .. 
                   }
    
            return meta;
        }
    }
    

    Then you have to set that in the Global.asax.cs

    protected void Application_Start()
    {
       RegisterRoutes(RouteTable.Routes);
       ModelMetadataProviders.Current = new CustomModelMetadataProvider();
    }
    

    I’m assuming that you want to set only the display name from db but suppose you want to load the complete modelmetadata from db then I would suggest you to create a custom ModelMetadataProvider by implementing the abstract class ModelMetadataProvider.

    Hitting the database every time definitely not a good idea so we have to workout for some caching strategy.

    We have to hit the database for every new containerType (I guess) and read the metadata information for the container along with all its properties and store in the cache with key as the containerType (this could be a difficult job).

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

Sidebar

Related Questions

I want to provide a virtual webcam via DirectShow that will use the video
I want to provide a button which cancels the present task, Let's say I
I want to provide the ability to save some rendered data/charts (with the titles
I want to provide a task-based asynchronous pattern-style method. When awaiting the method, I
I want to provide styles changing for user in application. I have folder with
I want to customize the parameter in createuser() method Membership Provider, Actually, i have
I want sell some .NET library and I want provide edition with full source
I want to provide my user with some meaningful error messages when network requests
I want to provide my colleagues with an interface (using Windows Forms or WPF)
I want to provide a custom Batcher for Hibernate to use (for this reason:

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.