3

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; }

enter image description here 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.

  • Any console errors? – Steve Greene Oct 16 '17 at 19:45
  • @SteveGreene No console errors in chrome nor in visual studio... – Nick Burggraaff Oct 17 '17 at 08:03
  • Has my approach given you any insight or different case? Did you try to delete the min value? If it is working correctly (in the not posting values question) then maybe I can provide an example of setting the min value in a different way because I also have set a logic like this to my applications. – Anastasios Selmani Oct 17 '17 at 10:37
  • @AnastasiosSelmanis Thanks for the replies! Your approach sadly did not have any effect whatsoever on the issue... It is so frustrating because there no errors. When I submit the datetimepickerfor widgets are just being "selected" in the html instead of posting the data. When I remove the datetimepickers the post works fine. – Nick Burggraaff Oct 17 '17 at 11:31
  • Could you please add your Action method too? In order to reproduce it as efficiently as possible. – Anastasios Selmani Oct 17 '17 at 11:35

2 Answers2

3

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 )
)
  1. You are setting for the second datetimepicker as min value the Model.dtStartDatum. When the view renders I am guessing that the field doesn't have any value. You may set the value of the first datetimepicker to DateTime.Today but this doesn't mean that it will be read as such from the min attribute of the second datetimepicker. The value that is binded to the min value of the second datetimepicker may not allow some dates to bind to the model. The easiest way to check it is to open the datepicker and see if it allows you to select dates before today.
  2. 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)

  3. 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.

Anastasios Selmani
  • 3,579
  • 3
  • 32
  • 48
2

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.