Nick Burggraaff
Nick Burggraaff

Reputation: 93

Kendo DateTimePicker not posting asp.net MVC

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.

Upvotes: 3

Views: 4018

Answers (2)

Nick Burggraaff
Nick Burggraaff

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

Anastasios Selmani
Anastasios Selmani

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

Upvotes: 3

Related Questions