Localizing MVC3 Validation Messages

这一生的挚爱 提交于 2019-12-10 13:37:00

问题


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 =)


回答1:


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




回答2:


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.




回答3:


Just install the the dot net 4 full language pack in the desired language and you will get the localization of the DataAnnotations validation messages.



来源:https://stackoverflow.com/questions/6013805/localizing-mvc3-validation-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!