This is a migrated thread and some comments may be shown as answers.

model state validation for DateTime Input

5 Answers 3066 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Bina
Top achievements
Rank 1
Bina asked on 25 Jun 2017, 11:28 PM
I am using the Kendo DateInput inside my razor views as below

 <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

Sort by
0
Konstantin Dikov
Telerik team
answered on 28 Jun 2017, 02:27 PM
Hi Bina,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Bina
Top achievements
Rank 1
answered on 29 Jun 2017, 04:03 AM

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.

0
Konstantin Dikov
Telerik team
answered on 03 Jul 2017, 01:09 PM
Hi Bina,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
S
Top achievements
Rank 1
answered on 01 Aug 2017, 05:53 AM

I'm issuing the same problem. What might cause the problem?

 

 

 

0
Boyan Dimitrov
Telerik team
answered on 03 Aug 2017, 03:04 PM

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Date/Time Pickers
Asked by
Bina
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Bina
Top achievements
Rank 1
S
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or