c# - MVC .Net Core Model Validation - The value '' is invalid. Error -
i trying use model validation in mvc .net core , can't manage replace default error message 'the value '' invalid'.
in theory, can replace our own custom error message using errormessage
annotation in model. couldn't find way make 1 work.
my model
[required(errormessage = "date required")] [datatype(datatype.date, errormessage = "invalid date format")] [display(name = "appointment date")] [displayformat(dataformatstring = "{0:dd/mm/yyyy}", applyformatineditmode = true)] public datetime appointmentdate { get; set; }
i put different errormessage
both required
, datatype
tag shown in above.
my html view
<div class="col-md-2"> <input class="form-control" asp-for="appointmentdate"> <span asp-validation-for="appointmentdate" class="text-danger"></span> </div>
could please me how error message replaced? thanks.
in order make required
attribute works need make field nullable:
public datetime? appointmentdate { get; set; }
edit: note datatype
attribute doesn't perform validation on field. mvc validate date when applying binding post
data model
Comments
Post a Comment