Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localizing MVC3 Validation Messages

I'm trying to localize the validation messages of the data-annotations. I thought that it could be done as described here: Supporting ASP.NET MVC 3 Validation with Non-English Locales.

Now it says that ASP.NET MVC and types in the System.ComponentModel.DataAnnotations namespace use their own localized messages. So is that more or less useless to me and only a help for formatting for example prices?

But back to the real question, so the only way to localize the validation messages is doing something like this? localize default model validation in mvc 2

Just trying to get some clearification here, thanks =)

like image 237
Nischo Avatar asked May 16 '11 06:05

Nischo


2 Answers

The resources for the data annotations are in the .NET Framework 4. You have to install the language pack for the .NET Framework.

like image 180
slfan Avatar answered Oct 05 '22 02:10

slfan


You could use resource files:

public class UserViewModel
{
    [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(UserResources))]
    [Display(Name = "FirstName", ResourceType = typeof(UserResources))]
    public string FirstName { get; set; }
}

You may checkout the following blog post as well.

like image 25
Darin Dimitrov Avatar answered Oct 05 '22 02:10

Darin Dimitrov