ASP.NET MVC validation message does not get locali

2019-02-06 09:22发布

问题:

I am using ASP.NET MVC 4 with unobtrusive clientside validation. The language in my application is german (defined in the web.config file)

If i have a required field (configured with data-annotations in my Code First Classes), the client side validation works fine. the only downside: The Message is not Localized.

The Field XXXX is required.

Is there a solution out for this problem?

回答1:

You must install the .NET Framework Language pack, according to your .NET Framework version:

Microsoft .NET Framework 4.5 Language Pack: http://www.microsoft.com/de-de/download/details.aspx?id=30667

Microsoft .NET Framework 4 Full Language Pack: http://www.microsoft.com/de-de/download/details.aspx?id=23067

In these pages, check the requirements, in order to see if they meets your needs (i.e.: Operating System Version, x86 or x64, etc.). If they don't meet your needs, search on Google something like "Microsoft .NET Framework German Language Pack".



回答2:

Yes - reference your resource file in your validation attributes:

[Required(ErrorMesageResourceName="LastName", ErrorMessageResourceType=typeof(YourResourceClassName))]