【发布时间】:2012-06-09 06:07:03
【问题描述】:
我已经在 Visual Studio 中启动了一个默认的 MVC4 项目,
在我的模型中某处是这段代码
public class LoginModel
{
[Required]
[Display(Name ="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; }
}
我想把它改成这样,因为我想尝试本地化(在另一个类中有效,但在这里不可用)(用于本地化的字符串 = resx 文件)
public class LoginModel
{
[Required]
[Display(Name =strings.UserName)]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = strings.Password)]
public string Password { get; set; }
[Display(Name = strings.RememberMe)]
public bool RememberMe { get; set; }
}
错误是它必须是一个常量表达式,但是当我这样做时,我会得到类似“属性索引缺少访问器”之类的东西
我在这里错过了什么?为什么我不能只为该死的东西分配一个字符串值? 在 Java 中,这一切都容易得多。希望你能帮帮我。
【问题讨论】:
-
谢谢!!那个帖子解决了我的问题,我已经搜索过了,但我想我没有搜索正确。我不得不使用 [Display(ResourceType = typeof(strings), Name = "Gebruikersnaam")] 并且我将 strings.resx 属性全部公开
标签: c# asp.net-mvc variables static constants