2010-04-13 39 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