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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:52:32+00:00 2026-05-26T12:52:32+00:00

We are currently building a mid-sized intranet application using MVC3. One requirement is the

  • 0

We are currently building a mid-sized intranet application using MVC3. One requirement is the possibility to change and translate field names and labels on the fly. We are currently using extended versions of ViewPage, ViewMasterPage and ViewUserControl enriched by an translation helper injected by spring.net to achieve this requirement.

This solution solves all requirements except MVC features that rely on ModelMetadata (e.g. LabelFor). My first thought was that there should be an extension point to replace the current implementation. Luckily the MVC team build ModelMetadataProviders in a way that I can inject a custom translation aware DataAnnotationsModelMetadataProvider.

protected override ModelMetadata CreateMetadata( IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName )
{
  // Call the base method and obtain a metadata object.
  var metadata = base.CreateMetadata( attributes, containerType, modelAccessor, modelType, propertyName );

  if( containerType != null )
  {
    // Obtain informations to query the translator.
    var objectName = containerType.FullName;
    var displayName = metadata.GetDisplayName();

    // Query the translator.
    var translatedDisplayName = Translator.Translate( objectName, displayName );

    // Update the metadata.
    metadata.DisplayName = translatedDisplayName;
  }

  return metadata;
}

I’m using the containerType and GetDisplayName() as key to obtain a translation from a translation contributor (that uses caching, does not degrade performance), then calling base and change the returned ModelMetadata by updating the DisplayName property before returning it.

What makes me unconfident about this solution is that I can’t predict what side effects I have to expect? Or if there is a better, proper solution?

  • 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-26T12:52:33+00:00Added an answer on May 26, 2026 at 12:52 pm

    Yes, this is the valid usage.

    Make sure you derive from DataAnnotationsModelMetadataProvider as you do to reuse all the features it provides.

    You can also handle more custom attributes here – you can decorate your model with your own custom attributes and then update ModelMetadata based on them.

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

Sidebar

Related Questions

I currently building web management system using mvc3 In my application i have system
I am currently building an application using ASP.NET MVC. The data entry pages are
I'm currently building an application using entity framework. Normally I would use a stored
I am currently building a simple application for Android using the NDK and needs
I am currently building an application in PHP using CodeIgniter. Usually, in .NET applications,
we're currently building a data warehouse using OWB (Oracle Warehouse Builder). One of the
I am currently building an internal web application used in a factory/warehouse type location.
We're currently building an application that executes a number of external tools. We often
I'm currently building a small web application that includes a fair amount of JavaScript.
I am currently building an Excel 2007 Add-in using VSTO (latest version + sp1)

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.