Reputation: 93
Im trying to post a form containing a dropdown with values and a starting and ending date and time. The problem is that when i post the form, it basicaly doesnt post. Instead of posting it is selecting the dateTimePicker input (because of the blue border in the html result). I can't put my finger on what is wrong. Thanks in advance!
DateTimePicker partials
@(Html.Kendo().DateTimePicker()
.Name("dtStartDatum")
.Value( DateTime.Today )
.Format( "dd-MM-yyyy HH:mm" )
.TimeFormat( "HH:mm" )
.DateInput( true )
)
@(Html.Kendo().DateTimePicker()
.Name("dtEindDatum")
.Value( DateTime.Now)
.Format( "dd-MM-yyyy HH:mm" )
.TimeFormat( "HH:mm" )
.Min(Model.dtStartDatum)
.DateInput(true)
)
Viewmodel with the 2 DateTimes:
public IEnumerable<vmPar> parVoerpunt { get; set; }
public IEnumerable<vmPar> parKanaal { get; set; }
public IEnumerable<vmPar> parAlarm { get; set; }
[DataType( DataType.DateTime )]
public System.DateTime dtStartDatum { get; set; }
[DataType( DataType.DateTime )]
public System.DateTime dtEindDatum { get; set; }
public int afdelingId { get; set; }
public int afdelingIdSelected { get; set; }
public int stalId { get; set; }
EDIT
Somethimes it actually does post after repicking new dates like 10 times. When it posts it is the right value, but I don't know why it is not always posting.
Upvotes: 3
Views: 4018
Reputation: 93
I found my answer, sorry for the long wait, just reminded myself of this post.
Unobtrusive validation in Chrome won't validate with dd/mm/yyyy
This is my issue and my asnwer. The validator switched the month and day of month so that picking a date above day of week 12 gave an validation error (which was a very silent error, still can't find it). Really weird that the dd-mm-yyyy wont validate properly even if globalization is set up properly. Hope I can help someone.
Upvotes: 2
Reputation: 3689
I use kendo DateTimePickers in my project a lot. From what I see there are a few things that could lead you to your problem.
@(Html.Kendo().DateTimePickerFor(m => m.dtStartDatum)
.Name("dtStartDatum")
.Value( DateTime.Today )
.Format( "dd-MM-yyyy HH:mm" )
.TimeFormat( "HH:mm" )
.DateInput( true )
)
Since you appear to use a model with these fields you could use the DateTimePickerFor for the binding to the model fields. It is not wrond to use it the way you use it but since you insert a model in your view it is a better practice. (The example above)
I don't think that the dateInput is necessairy at your case. I don't think it affects anything in a bad way but it is not necessairy.
Upvotes: 3