views:

40

answers:

2

Hi there,

I want to localize the error message for wrong user inputs.

E.g. min. length of City name is 2 chars.

[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Validation))]
[StringLength(50, ErrorMessageResourceName = "Max", ErrorMessageResourceType = typeof(Validation))]
[RegularExpression(".{2,}", ErrorMessageResourceName = "Min", ErrorMessageResourceType = typeof(Validation))]
public string City { get; set; }

The error resource string currently looks like: "Not enough characters."

Now I want to add a more specific error message e.g. "Minimum 2 characters required".

But how can I pass in an argument to a localized resource string like "Minimum {0} characters required" by using ErrorMessageResourceName and e.g. String.Format() ?

Thank you!

A: 

Globalizing ASP.NET MVC Client Validation
http://haacked.com/archive/2010/05/10/globalizing-mvc-validation.aspx

Also look at the other two posts Phil has linked in that post.

Robert Harvey
The thing is that everything is working except for localized error messages which take a few arguments for formatting the output string. I wasn't able to figure it out yet how to achieve that.
sde