I am new to MVC and ask a question about validation. Is there a way to dynamically set an error message?
For example, how can I achieve the following (ignore the hardcoded 50, this may be due to Web.config or specific to the current log).
[MetadataType(typeof(DocumentValidation))] public partial class Document { public class DocumentValidation { private const int MaxLength = 50; [Required(ErrorMessage = "Document Title is required")] [StringLength(MaxLength, ErrorMessage = "Must be under " + MaxLength.ToString() + " characters")] public string Title { get; set; } }
}
Thanks,
source share