首页 技术 正文
技术 2022年11月13日
0 收藏 663 点赞 3,307 浏览 1462 个字

这个是我们常见的AccountModel代码

   public class ChangePasswordModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Current password")]
public string OldPassword { get; set; } [Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; } [DataType(DataType.Password)]
[Display(Name = "Confirm new password")]
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
} public class LoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; } [Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; } [Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}

如果要支持多语言,要怎么做呢, 看这个例子

    public class AddPointModel
{
[Required(ErrorMessageResourceType = typeof(ErrMsg),ErrorMessageResourceName="MobileRequire")]
[DataType(DataType.PhoneNumber)]
[Display(Name = "Mobile", ResourceType = typeof(Re))]
public string Mobile { get; set; } [Required(ErrorMessageResourceType = typeof(ErrMsg), ErrorMessageResourceName = "CodeRequire")]
[Display(Name = "积分码")]
public string JfCode { get; set; }
}

  Require 里面本身就支持从资源文件里读取语言信息。 只要在APP_GlobalResources里建Resource文件,指定文件类名,Key就可以了。

但是Display这样写就不行。因为默认的Resource文件的Key是Internal的,访问不了。

需要把Resource文件不要放在APP_GlobalResources里,改为嵌入的资源,自定义工具改成PublicResXFileCodeGenerator

DataAnnotations里DisplayAttribute和 ValidationAttribute 如何从资源文件读取信息,显示多语言

请参考这里 http://stackoverflow.com/questions/2431333/displayname-attribute-from-resources

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,738
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,129
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292