Los mensajes de validación localizados de ASP.NET MVC 3 funcionan en mi máquina, pero no en el servidor

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-required="Das Feld &amp;quot;Adresse&amp;quot; ist erforderlich." 
   id="Address" name="Address" type="text" value="" 

Esto funciona bien en mi maquina when I set my CurrentThread to an English, German or Italian CultureInfo.

Pero 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?

preguntado el 09 de marzo de 12 a las 15:03

Are you using the default validation strings or do you have your own resources? -

@linkerro I'm using the default strings. I use localized display names though -

How do you set the current culture? Using web.config Globalization or some other way? -

@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 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. -

2 Respuestas

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.

respondido 15 mar '12, 08:03

Se trata de un "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.

Respondido 19 Feb 17, 02:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.