1

Possible Duplicate:
ASP.net MVC - Custom attribut error message with nullable properties

Can I replace default validation message for integer field? I want to localize it. (For int: "The field Id must be a number.")

Community
  • 1
  • 1
Roman Bats
  • 1,737
  • 3
  • 28
  • 39

1 Answers1

0

You could use the ErrorMessageResourceName property:

[Required(ErrorMessageResourceName = "SomeResource")]
[StringLength(30, ErrorMessageResourceName = "SomeOtherResource")]
public string Name { get; set; }

You may checkout this blog post for an example.

In response to this

How can I apply it for integer validation?

Firstly how are you validating integers ? Show us some code.

If your are using Regular expressions then use

 [RegularExpression("pattern", ErrorMessageResourceName = "SomeResource")]

or if you are using a custom attribute, you can use this in similar fashion.

Yasser Shaikh
  • 45,616
  • 44
  • 197
  • 276