Thursday, 2 November 2017

MVC - How to display proper name in Validation error message

Watch this example on YouTube



Replace
        [Required(ErrorMessage ="this field is mandatory")]
        public string Name { get; set; }

with
        [Required(ErrorMessage ="{0} field is mandatory")]
        public string Name { get; set; }

or even with
        [Display(Name="Modified Name")]
        [Required(ErrorMessage ="{0} field is mandatory")]
        public string Name { get; set; }

No comments:

Post a Comment