问题
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 &quot;Adresse&quot; muss eine Zeichenfolge mit
einer maximalen L&#228;nge von 100 sein."
data-val-length-max="100"
data-val-required="Das Feld &quot;Adresse&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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/9636332/asp-net-mvc-3-localized-validation-messages-work-on-my-machine-but-not-on-serve