views:

339

answers:

1

i have an asp.net mvc application, and i use data annotations for data validations something like this:

 public class Booking
 {
    [Required(ErrorMessage = "Please enter your name")]
    public string Name { get; set; }
     ...

so this is in my DomainModel and i need to translate the ErrorMessage, and to use the translation in my views

i would like to have just one resource file for each language

anybody knows some solutionus ?

+2  A: 

Put your error messages in resource files, and apply ErrorMessageResourceName and ErrorMessageResourceType instead of ErrorMessage on the Required attribute. See here: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.requiredattribute_members.aspx

Konamiman
how is it going to know wich language to pick, these classes are in the data model which is a separate class library (not in UI)
Omu
Maybe you can inject some sort of user context?
Miau