How to replace standard DataAnnotations error messages

后端 未结 3 1793
小蘑菇
小蘑菇 2021-01-18 03:56

I\'m using System.ComponontModel.DataAnnotations to validate my model objects. How could I replace messages standard attributes (Required and StringLength) produce without p

3条回答
  •  清歌不尽
    2021-01-18 04:47

    You can use ErrorMessage property of base class ValidationAttribute for all DataAnnotations validators.

    For example:

    [Range(0, 100, ErrorMessage = "Value for {0} must be between {1} and {2}")]
    public int id;
    

    Maybe it'll help.

提交回复
热议问题