1

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!

sde
  • 123
  • 1
  • 5
  • check this link [http://stackoverflow.com/questions/2347650/how-to-use-dataannotations-errormessageresourcename-with-custom-resource-solution](http://stackoverflow.com/questions/2347650/how-to-use-dataannotations-errormessageresourcename-with-custom-resource-solution) – Xulfee Jul 21 '10 at 07:55

1 Answers1

0

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
  • 178,213
  • 47
  • 333
  • 501
  • 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 Jul 12 '10 at 15:57