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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:23:36+00:00 2026-06-08T00:23:36+00:00

When using DataAnnotations.Display attribute combined with localized strings, the syntax which is used is

  • 0

When using DataAnnotations.Display attribute combined with localized strings, the syntax which is used is the following:

public class Customer
{
    [Display(ResourceType = typeof(DisplayResources), Name = "LName")]
    public string LastName { get; set; }
}

Source: MSDN.

Apparently, the following syntax is impossible:

public class Customer
{
    [Display(Name = DisplayResources.LName)]
    public string LastName { get; set; }
}

since it results in the following compile error:

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

What else I can do to avoid passing variables by their names through a string? Is there a way to avoid stringly-typed code?

  • 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-08T00:23:38+00:00Added an answer on June 8, 2026 at 12:23 am

    there is an article form ex-Telerik member Kazi Manzur Rashid. Localization with ASP.NET MVC ModelMetadata. He is explaining there how to use nice framework MvcExtensions (help articles)

    Here is an example:

    public class ProductEditModelConfiguration : ModelMetadataConfiguration<ProductEditModel>
    {
        public ProductEditModelConfiguration()
        {
            Configure(model => model.Id).Hide();
    
            Configure(model => model.Name).DisplayName(() => LocalizedTexts.Name)
                .Required(() => LocalizedTexts.NameCannotBeBlank)
                .MaximumLength(64, () => LocalizedTexts.NameCannotBeMoreThanSixtyFourCharacters);
    
            Configure(model => model.Category).DisplayName(() => LocalizedTexts.Category)
                .Required(() => LocalizedTexts.CategoryMustBeSelected)
                .AsDropDownList("categories", () => LocalizedTexts.SelectCategory);
    
            Configure(model => model.Price).DisplayName(() => LocalizedTexts.Price)
                .FormatAsCurrency()
                .Required(() => LocalizedTexts.PriceCannotBeBlank)
                .Range(10.00m, 1000.00m, () => LocalizedTexts.PriceMustBeBetweenTenToThousand);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an MVC2 app using DataAnnotations. I have a following Model: public class
Model: using System.ComponentModel.DataAnnotations; using MySite.Validators; namespace MySite.Models { public class AddItem { [Required(ErrorMessage =
I'm using DataAnnotations attributes to validate my model objects. My model class looks similar
We put all of our DataAnnotations on our Model class Customer. We then expose
I'm using DataAnnotations for validation of a custom class (LINQ to SQL auto generated)
I am using DataAnnotations for my model validation i.e. [Required(ErrorMessage="Please enter a name")] public
Look at the following code, I am using the required(System.ComponentModel.DataAnnotations) namespace but it keeps
I'm using dataannotations in an MVC2 app and am a little discouraged when trying
Is there any way to validate using DataAnnotations in WPF & Entity Framework?
I am currently using MVC 1.0 and .NET 3.5. I am using DataAnnotations to

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.