<span>Date of Birth</span>
@(Html.Kendo().DateInput().Name("Patient.Dob").Format("dd-MMM-yyyy").Min(new DateTime(1900, 1, 1))
.Max(DateTime.Today).Messages(m => m.Year("yyyy").Day("dd").Month("mmm")))
When the date of birth is not entered, the model state validation fails as it tries to validate the placeholder value - ("dd-MMM-yyyy")
How can i specify the placeholder, such that it does not do model state validation
5 Answers, 1 is accepted
You should either make the DateTime filed nullable or set the Required attribute in the model for that field:
[DisplayName("Last supply")]
[DataType(DataType.Date)]
public DateTime? Dob
{
get;
set;
}
or
[Required]
[DisplayName("Last supply")]
[DataType(DataType.Date)]
public DateTime Dob
{
get;
set;
}
Hope this helps.
Regards,
Konstantin Dikov
Progress Telerik
Thanks for your response.
I have already set the DateTime field as nullable as below
[Display(Name = "Date of Birth")]
[Column("DOB", TypeName = "date")]
[DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime? Dob { get; set; }
The problem is that, during the postback, the raw value available in the model is dd-mmm-yyyy and hence the modelState.Valid returns false in the Controller method.
Note: the model holds the value null. But the raw value is dd-mmm-yyyy. model validation error states that the format dd-mmm-yyyy is not a valid date.
Could you please open a regular support ticket and attach a sample, runnable project replicating the issue, because on my local tests I was not able to replicate the issue in question?
Best Regards,
Konstantin Dikov
Progress Telerik
I'm issuing the same problem. What might cause the problem?
Hello,
We would need a sample runnable sample project to investigate it locally. Since you are not able to attach projects in the forum I would suggest to open a support ticket and attach the project in the ticket.
Regards,Boyan Dimitrov
Progress Telerik