开发者

Dataannotation error messages

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜