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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:21:26+00:00 2026-06-08T12:21:26+00:00

not sure why, but the data annotation in MVC3 insist on having constant values,

  • 0

not sure why, but the data annotation in MVC3 insist on having constant values, which i just can’t understand for things like error messages and display names. I love these annotations, they are so easy to use and so powerful, but what if you need to support multiple languages?

Imagine i have the following model:

public class Person
{
    public string First_Name { get; set; }
}

If i dont change anything and use the CRUD views that MVC3 will build for me I get a label next to the text fields that says “First_Name”, so i add the data annotation to change the display name like so:

public class Person
{
    [Display(Name="First name")]
    public string First_Name { get; set; }
}

Which works just fine. But i want to supply a different display name depending on the users language, using a function i made previously GetDisplayName(string ToGet, string Language) which just returns the string i am interested in, but if i change my data annotation to this:

public class Person
{
    [Display(Name=GetDisplayName("First_Name", "English"))]
    public string First_Name { get; set; }
}

Then i get a compiler error telling me that the annotation requires a constant values, WHY????

Does anyone know a way to accomplish what i am trying to do? Thanks

UPDATE

Ok, it appears that the best way to do this is with .resx resource files as per several answers below and those in other posts. which works great for the most part.

Does anyone know how i can request a resource with a variable name? not in the context of data attributes this time, but just in controllers and views.

Basically at the moment i am getting at the resources with @Resources.SomeKey but i would like to be able to use that within a function in a @Resources["SomeOtherKey"] where SomeOtherKey is a dynamically generated string.

  • 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-08T12:21:28+00:00Added an answer on June 8, 2026 at 12:21 pm

    If you have your translated property names in Resource Files, that is supported out of the box… no need to extend the framework.

    Just use:

    [Display(Name = "Resource_Key", ResourceType = typeof(DataFieldLabels))]
    public string myProperty { get; set; }
    

    Where the “Resource_Key” is the key in your resource files… and the “DataFieldLabels” is the name of your base resource file.

    EDIT:

    In order to access resource files dynamically you can do:

    ResourceSet resset = ResourceManager.GetResourceSet(culture, true, false);
    var translated = resset.GetString("myToken")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looping my object data but am getting this undefined value. Not sure why
I am fairly new to MVC but not sure exactly which Redirect... replaces the
Not sure what this is called, but is there a way I can pull
I am not sure why but I just installed SQLdeveloper 32 bit (3.0.0.4). When
I am using D-Day calendar and I am not sure but I got a
I am not sure why but jQuery find function is not able to find
I'm not totally sure but this looks wrong: I have a header file named
I know what i want but not sure of the name and required tools
I'm starting out with MVC but not sure it's the best option. I need
I'm not sure that title is worded very well, but not sure how else

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.