Why can't I use resources as ErrorMessage with DataAnnotations?

前端 未结 6 1975
眼角桃花
眼角桃花 2020-12-05 05:15

Why can\'t I do like this?

[Required(ErrorMessage = \"*\")]
[RegularExpression(\"^[a-zA-Z0-9_]*$\", ErrorMessage = Resources.RegistrationModel.UsernameError)         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 05:44

    You should instead look at the ErrorMessageResourceName and ErrorMessageResourceType properties of this attribute. They do allow the error message to be pulled from a resource.

提交回复
热议问题