开发者

Dataannotation error messages

开发者 https://www.devze.com 2023-02-15 06:40 出处:网络
All of the DataAnnotation validation attributes can take a named parameter ofErrorMessageResourceType and ErrorMessageResourceName to specify an error message when vaildation fails:

All of the DataAnnotation validation attributes can take a named parameter of ErrorMessageResourceType and ErrorMessageResourceName to specify an error message when vaildation fails:

        [Display(Name = "Stock开发者_如何学Go Date")]
        [Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = "Required")]
        public DateTime StockDate { get; set; }

Is there any advantage to using these named parameters instead of referencing the resource directly?

        [Display(Name = "Stock Date")]
        [Required(ErrorMessage = ValidationMessages.Required)]
        public DateTime StockDate { get; set; }

I haven't used resource files much before this project so there could be something I'm missing but referencing the resource directly seems a lot cleaner as well as catching typos with Intellisense.

0

精彩评论

暂无评论...
验证码 换一张
取 消