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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:59:53+00:00 2026-05-20T20:59:53+00:00

This is the problem that we’re facing in .NET MVC 2. We’re trying to

  • 0

This is the problem that we’re facing in .NET MVC 2.

We’re trying to use DataAnnotations to take care of the Model Validation for us, like it’s supposed to. The only problem that we’re having is that we don’t want the standard error messages (because we have multiple languages on our website).

We want to localize this, but the way the site is setup, is that all text comes from a database. So we’d like to have our error messages in the database as well.

So we wrote a custom RequiredAttribute, like this:

public class LocalizedRequiredAttribute : RequiredAttribute
{   
    public string LocalizedErrorMessage
    {
        get
        {
            return ErrorMessage;
        }
        set
        {
            ErrorMessage = value.Translate();
        }
    }

}

We wrote an extension to the String class to add the “Translate()” method, which does the necessary database lookup for the correct localized version.

We use our attribute like this:

[LocalizedRequired(LocalizedErrorMessage = "Naam is required")]
public string Name {get; set; }

This works, but only once.

If you visit the site in French first, you’ll see the French error message stating that you’re supposed to enter a value. If you visit the English site later, you’ll still see the French error on the English page. The Setter seems to be called only once.

What can we do to prevent this behavior and refresh the error message every time the validation is run / the model is populated with values?

Thanks for any help you can give me.

  • 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-20T20:59:54+00:00Added an answer on May 20, 2026 at 8:59 pm

    Couldn’t you fix this by moving your .Translate() from your setter to your getter? It makes sense that your setter is called only once.

    Edit:
    I assumed ErrorMessage was a virtual message, which is not the case.

    Your only option might be to create Resource class (you don’t need a resource file) that retrieves your values from the database.

    [Required(ErrorMesageResourceName="FirstName", ErrorMessageResourceType=typeof(ABCResourceClass))]  
    public string Name {get; set; } 
    
    class ABCResourceClass{
      public static String  FirstName{
        get{
            return Translate("FirstName");
        }
      }
    
    }
    

    As you can infer from the example, the annotations framework calls the property with the name that matches the string you provide to ErrorMessageResourceName.

    You could resort to some kindof code generation technique to create the ABCResourceClass if you have a lot of properties.

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

Sidebar

Related Questions

So we have this problem that we are trying to figure out. Heres what
I have this problem that i have code like this in many of my
This problem is for a piece of software that is use by companies that
I've got this problem that It always hit the PropertyAccessException when trying to saveOrUpdate();
So I'm trying to solve this problem that asks to look for palindromes in
I am facing this problem that buttons in android are not clickable when given
Ok I have this problem that I've never had before, it's really bugging me.
I have this problem that my sites uses alot of ajax and when a
There was this problem that has been asked about implementing a load byte into
The background to this problem is that I'm doing a computing project which involves

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.