I am using translation from resx files stored in App_GlobalResources folder with DataAnnotations in a mvc3 model.
It works fine with a Required DataAnnotation, but it doesn’t work any more if i’m trying to use the Display DataAnnotation.
Here is my code:
[Required(ErrorMessageResourceType = typeof(Resources.Error), ErrorMessageResourceName = "RequiredClientName")]
[Display(Prompt = "ClientName", ResourceType = typeof(Resources.Front))]
public string Name { get; set; }
A System.InvalidOperationException is thrown only when I put the Display DataAnnotation
Here is the full exception(I am sorry, I didn’t find a way to translate it in english):
Impossible de récupérer la propriété ‘Prompt’ en raison de l’échec de
la localisation. Le type ‘Resources.Front’ n’est pas public ou ne
contient pas une propriété de chaîne statique publique avec le nom
‘FooterAbout’.Description : Une exception non gérée s’est produite au moment de
l’exécution de la requête Web actuelle. Contrôlez la trace de la pile
pour plus d’informations sur l’erreur et son origine dans le code.Détails de l’exception: System.InvalidOperationException: Impossible
de récupérer la propriété ‘Prompt’ en raison de l’échec de la
localisation. Le type ‘Resources.Front’ n’est pas public ou ne
contient pas une propriété de chaîne statique publique avec le nom
‘FooterAbout’.
The model I am using is stored in an Area.
Also, I can access values in my resx files from the _Layout, or in the Required DataAnnotation
Thank you for your help
Florent.
The error message is pretty self explanatory (which I am translating for the non-French speaking audience of the site):
You should make the resource file public by setting the Custom Tool to
PublicResXFileCodeGeneratorand the Build Action toEmbedded Resourcein the properties of your RESX file:The reason for that is because by default the generated strongly typed class is internal and not accessible by Razor views which are compiled into a separate assembly at runtime.