views:

34

answers:

1

I followed the techique ASP.NET MVC 2: Model Validation from Scott Gu. (http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx).

However I am building a localised web site. How can I localized the error string?

I tried the following by replacing the following:

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

With the following:

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

but I get a complilation error:

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

Please help!

+1  A: 

I found it so I am just posting it in case someone ever wants to know how it is done:

[RegularExpression(@"\d{4}", ErrorMessageResourceName= "search_error1", ErrorMessageResourceType = typeof(Resources.SharedStrings))] public Nullable YearOfWork { get; set; }

gmang
+1 for bothering to post the answer
Dan Diplo