Passing the select value back to Server

2 posts, 0 answers
  1. Jay
    Jay avatar
    5 posts
    Member since:
    Feb 2008

    Posted 17 Mar 2013 Link to this post

    So is this the only way to pass the value that has been selected back to the server ...seems like way too much glue code , I have to have a hidden field, then need to use JS to fill that field etc etc

    Jay

    <body>
        @using (Html.BeginForm("Index", "Home", FormMethod.Post))
        {
            @Html.HiddenFor(m => m.StartDate)
     
            @(Html.Kendo().Calendar()
                      .Name("calendarStart")
                      .Value(DateTime.Now)
                  )
             
            @Html.HiddenFor(m => m.EndDate)
     
            @(Html.Kendo().Calendar()
                      .Name("calendarEnd")
                      .Value(DateTime.Now)
                      )
             
            <button name="button" value="save">Save Date</button>
        }
     
        <script>
            $(document).ready(function () {
     
                var calendarStart = $("#calendarStart").data("kendoCalendar");
                $("#StartDate").val((moment(calendarStart.value()).format("YYYY-MM-DD")));
     
                calendarStart.bind("change", function (e) {
                    $("#StartDate").val((moment(this.value())).format("YYYY-MM-DD"));
                 
                });
     
                var calendarEnd = $("#calendarStart").data("kendoCalendar");
                $("#EndDate").val((moment(calendarEnd.value()).format("YYYY-MM-DD")));
     
                calendarEnd.bind("change", function (e) {
                    $("#EndDate").val((moment(this.value())).format("YYYY-MM-DD"));
                });
     
            });
        </script>
    </body>
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 19 Mar 2013 Link to this post

    Hello Jay,

    If you want to submit the value to the server consider using the DatePicker widget other way you will have to go this way and create the hidden field which to be submitted.

    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top