实体框架数据注释和多语言

时间:2012-05-07 13:43:06

标签: entity-framework entity-framework-4 globalization

我的实体有这个代码。

我想知道是否有办法根据用户选择的语言替换硬编码文本,并参考资源文件。

public class Applicant
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ApplicantID { get; set; }

        [Required(ErrorMessage = "Name is required")]
        [StringLength(20, MinimumLength = 3, ErrorMessage = "Name should not be longer than 20 characters.")]
        [Display(Name = "First and LastName")]
        public string Name { get; set; }

1 个答案:

答案 0 :(得分:4)

您正在谈论Localization.Check this

http://adamyan.blogspot.com/2010/02/aspnet-mvc-2-localization-complete.html

 [Display(Name = "Email", ResourceType = typeof(Localization))]
 [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Localization))]
 [Email(ErrorMessageResourceName = "EmailFormatError", ErrorMessageResourceType = typeof(Localization))]
 public string Email { get; set; }