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 Answer 1

2

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; }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.