Hi Frederic,
Thanks for contacting Syncfusion Support.
Query1: When I submit my form, the result is Something like this: "01/01/0001 00:00:00"
Answer: The date value will become “01/01/0001 00:00:00” because of defining the model value as DateTime type. This is because the DateTime type can’t accept null value, hence it will automatically change to the min value (01/01/0001 00:00:00) instead of null. So please define the model variable as a nullabe DateTime type by adding a question mark next to the type of the variable in the model class as shown in the below code snippet.
|
public class ModelValues
{
[Required(ErrorMessage = "Valid Date is Required")]
public DateTime? DateValue { get; set; }
} |
Query2: I tried to add this: <span asp-validation-for="dtDateDemarrage" class="text-danger"></span> But it Don't works either.
Answer: We suspect the cause for this issue may be the value of asp-validation-for attribute might be misspelled or a wrong value instead of assigning the model variable name. So please ensure that the model variable name assigned for the DatePicker component is assigned as the value for the asp-validation-for attribute as shown in the below code snippet.
|
<ej-date-picker id="datepick" ej-for="@Model.DateValue" ></ej-date-picker>
<span asp-validation-for="DateValue" class="text-danger"></span> |
For your convenience, we have attached a simple sample for validating the DatePicker component in the below link. Please check it.
To know more about validating the DatePicker component at server side, please check the below documentation link.
Regards,
Deepa L.