6

I'm using localized validation messages in a ASP.NET MVC 3 form. It correctly generates HTML like

<input class="inputlong" data-val="true" 
   data-val-length="Das Feld &amp;quot;Adresse&amp;quot; muss eine Zeichenfolge mit
                  einer maximalen L&amp;#228;nge von 100 sein." 
   data-val-length-max="100" 
   data-val-required="Das Feld &amp;quot;Adresse&amp;quot; ist erforderlich." 
   id="Address" name="Address" type="text" value="" 
/>

This works fine on my machine when I set my CurrentThread to an English, German or Italian CultureInfo.

But it doesn't work on two other developer machines and a Windows Server 2008 R2 test machine (same project, same setup: I've even installed the ASP.NET MVC 3 Tools Update Language Packs), but I still get only the English validation messages:

 <input class="inputnormal input-validation-error" data-val="true" 
     data-val-length="The field Adresse must be a string with a maximum length of 100." 
     data-val-length-max="100" data-val-required="The Adresse field is required." 
     id="Address" name="Adresse" type="text" value=""
 />

Are there settings or some missing assemblies on the other computers I am not aware of?

splattne
  • 102,760
  • 52
  • 202
  • 249
  • Are you using the default validation strings or do you have your own resources? – linkerro Mar 09 '12 at 15:12
  • @linkerro I'm using the default strings. I use localized display names though – splattne Mar 09 '12 at 15:22
  • How do you set the current culture? Using web.config Globalization or some other way? – archil Mar 15 '12 at 08:12
  • @archil I set the current thread's cultureinfo on every request in my base controller (according to the user's choice). Like I said in my question: It perfectly works on my dev machine. – splattne Mar 15 '12 at 09:34
  • @splattne In my answer, I meant installing language pack on other dev's and server machines. Until installation It wouldn't work on my dev machine too. – archil Mar 15 '12 at 10:06

2 Answers2

8

You may have to install .net framewok language pack. For example, on my machine validation messages would not show up in German until I installed German language pack.

Required attribute is not part of asp.net-mvc but more general DataAnnotations, so language pack should help.

archil
  • 39,013
  • 7
  • 65
  • 82
0

It's a "few years later", but I would like to give my 2 cents on this. I recently had this same problem but with current technology stack: VS 2015, MVC 5, .NET 4.6; we're developing in México and there was a language mixup with some of the validation error messages (majority in Spanish and a few in English).

I found this SO answer but it didn't help my situation because when I tried to install .NET language pack, the installer throw me a "you have a more recent version installed" message and the installation halted!

The way I fixed this was by installing the MVC language pack with Nuget for our project: Microsoft.AspNet.Mvc.es (obviously there are localized packages for all the Microsoft supported languages: just replace .es with your own language, e.g. Microsoft.AspNet.Mvc.de for German). After that our application showed all validation errors in Spanish without any further configuration.

I hope this helps somebody with the same issues.

Fer García
  • 940
  • 1
  • 14
  • 32