I'm new to MVC and have a question regarding validation. Is there a way to dynamically set the Error Message?
For example, how could I achieve the following (ignore the hardcoded 50, this could come from the Web.config or specific to the current logged).
[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,