【发布时间】:2013-08-31 12:05:19
【问题描述】:
通常为 ASP.NET MVC 3 Membership 生成的代码,尤其是 ChangePasswordModel 类的属性 NewPassword 大致如下:
[Required]
[StringLength(100, MinimumLength=6)]
[DataType(DataType.Password)]
[Display("Name = CurrentPassword")]
public string NewPassword { get; set; }
为了使用外部参数填充一些信息,我正在使用 RecourceType:
(在这种情况下,我正在更改 OldPassword 并使用来自资源的一些额外数据填充属性 Display
[Required]
[DataType(DataType.Password)]
[Display(ResourceType = typeof(Account), Name = "ChangePasswordCurrent")]
public string OldPassword { get; set; }
返回NewPassword。 如何将MinimumLenght 替换为Membership.MinRequiredPasswordLength?:我的尝试:
[Required]
[StringLength(100, MinimumLength=Membership.MinRequiredPasswordLength)]
[DataType(DataType.Password)]
[Display(ResourceType=typeof(Account), Name= "ChangePasswordNew")]
public string NewPassword { get; set; }
这会产生错误:
属性参数必须是常量表达式,typeof 表达式 或属性参数类型的数组创建表达式 (http://msdn.microsoft.com/de-de/library/09ze6t76%28v=vs.90%29.aspx)
【问题讨论】:
-
谢谢。我只是将常量外包给我的 GlobalVariables 类,一切都很好。这似乎是最简单的方法
-
@NiklasS。这确实是最快的方法,+1
标签: c# asp.net asp.net-mvc-3 localization asp.net-membership