Data binding

6 posts, 0 answers
  1. Peter
    Peter avatar
    27 posts
    Member since:
    Jul 2019

    Posted 01 Aug 2019 Link to this post

    Since you would have a start and end date, how do you set up the control for DateRangePickerFor to bind to 2 fields. 

    I really like the 2 calendar view with the DateRange Picker but struggling on how to wire up the binding for the post back to the controller.

    Thanks

    Peter

  2. Peter
    Peter avatar
    27 posts
    Member since:
    Jul 2019

    Posted 02 Aug 2019 in reply to Peter Link to this post

    I figured out the syntax with both DateRangePickerFor and DateRangePicker using the StartField and EndField.
  3. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5446 posts

    Posted 05 Aug 2019 Link to this post

    Hello Peter,

    You are correct that these two fields need to be set.

    For anyone else having similar questions, the following KB article shows how to bind the range picker to a model, and how to POST its data back to the controller: https://docs.telerik.com/aspnet-core/knowledge-base/daterangepicker-bind-to-model-and-post.


    Regards,
    Marin Bratanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  4. Hassan
    Hassan avatar
    153 posts
    Member since:
    Aug 2010

    Posted 03 Mar in reply to Peter Link to this post

    Could you show how you managed to bind using the DateRangePickerFor, please?
  5. Peter
    Peter avatar
    27 posts
    Member since:
    Jul 2019

    Posted 03 Mar in reply to Hassan Link to this post

    Does this help?

     

                @(Html
                    .Kendo()
                        .DateRangePickerFor(item => item.StartDate,
                            item => item.EndDate
                        )
                        .Events(ev => ev.Open("jsCalendarOpened"))
                        .HtmlAttributes(new { style = "width: 100%" })
                        .Name("DateRangePicker")
                        .Format("MM/dd/yyyy")
                )

  6. Nikolay
    Admin
    Nikolay  avatar
    181 posts

    Posted 05 Mar Link to this post

    Hello Hassan,

    The syntax for binding the DateRangePickerFor to specific fields in the Model provided from Peter is correct:

    @(Html.Kendo().DateRangePickerFor(
               picker=>picker.StartDate,
               picker=>picker.EndDate)
    	.HtmlAttributes(new { style = "width: 100%; font-size:11px;", title = "daterangepicker"  })
    )

    This will be updated shortly in the article Marin has pointed to so others could benefit from it.

    Let me know if anything further arises.

    Regards,
    Nikolay
    Progress Telerik

    Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
Back to Top