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.
精彩评论