2010-04-13 52 views
1

我遵循Scott Gu的技术ASP.NET MVC 2:Model Validation。 (http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx)。ASP.NET MVC验证 - 错误字符串的本地化

但是我建立了一个本地化的网站。我怎样才能本地化错误字符串?

我试图通过更换以下以下:

[RegularExpression(@"\d{4}",ErrorMessage="Must be a 4 digit year")] 
public Nullable<int> YearOfWork { get; set; } 

下列要求:

[RegularExpression(@"\d{4}",ErrorMessage=Resources.SharedStrings.search_error1)] 
public Nullable<int> YearOfWork { get; set; } 

但我得到一个错误complilation:

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

请帮帮忙!

回答

2

我发现它,所以我刚刚张贴的情况下,曾经有人想知道它是怎么做的:

[正则表达式(@ “\ d {4}”,ErrorMessageResourceName = “search_error1”,ErrorMessageResourceType = typeof运算(Resources.SharedStrings))] public Nullable YearOfWork {get;组; }

+0

+1用于打扰发布答案 – 2010-04-14 14:34:08