Presuming we have a model like so:
public class TheViewModel
{
public string DateTime? Image_Date { get; set; }
}
And it is added to a Razor view like so:
Html.TextBoxFor(model => model.Image_Date)
Then the following is rendered in the browser:
<input data-val="true" data-val-date="The field Image_Date must be a date." id="Image_Date" name="Image_Date" type="text" value="" />
The attribute data-val-date
is what I'm interested in. It's plainly being injected in by MVC's "unobtrusive" jQuery validation integration.
So, what data annotation will override the verbiage in the HTML attribute?
For instance, [Required(ErrorMessage="This field is required!")]
will override the standard "The field {0} is required." message.
Failed attempts:
[DataType(DataType.Date, ErrorMessage = "Must be a valid date.")]
doesn't appear to do anything to client-side validation.[DisplayName("...")]
changes the wildcard portion of the pattern, but obviously doesn't affect the pattern itself.