Reputation: 7605
Here is a snippet from my Model class
[Required]
[DataType(DataType.Date)]
[Display(Name = "Birth Day")]
public DateTime customerBirthDate { get; set; } = DateTime.Today;
Here is a snippet from my razor file
<div class="wrap-input100 validate-input">
<span class="label-input100">Date of Birth</span>
<InputDate class="input100" id="birthday" name="birthday" @bind-Value="CurrentCustomerSubmission.customerBirthDate" />
<ValidationMessage For="@(() => Model.customerBirthDate)" />
</div>
When i delete the date from the InputDate field, I am expecting it to say
"The Birth Day field must be a date."
but what I am actually seeing is
"The customerBirthDate field must be a date."
I tested it in Chrome
Upvotes: 1
Views: 824
Reputation: 124
[Required(ErrorMessage ="{0} field is Required"]
[DataType(DataType.Date,ErrorMessage = "{0} field must be a date.")]
[Display(Name = "Birth Day")]
public DateTime customerBirthDate { get; set; } = DateTime.Today;
You can use error message for the required attribute
Upvotes: 0
Reputation:
You can do it like this
[Required]
[DataType(DataType.Date,ErrorMessage = "The Birth Day field must be a date.")]
[Display(Name = "Birth Day")]
public DateTime customerBirthDate { get; set; } = DateTime.Today;
Upvotes: 1