What is the best way to post data back. I am doing this now, is this good ?

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

    Posted 15 Mar 2013 Link to this post

    Here is how my code looks on a MVC app. 

    <body>
        @Html.Kendo().Calendar().Name("calendarstart").Value(DateTime.Now)
        <button id="save">Set date</button>
        <script>
            $(document).ready(function () {
                $("#save").click(function () {
                    var startDate = $("#calendarstart").data("kendoCalendar");
                    $.post("/Home/Index", { StartDate: startDate.value() });
                });
            });
        </script>
    </body>

    The issue i see is that their is no tight binding like what you have on MVC view model binding. 

    Jay

  2. Jay
    Jay avatar
    5 posts
    Member since:
    Feb 2008

    Posted 16 Mar 2013 Link to this post

    So do i have to go to this much trouble to pass data back to the server ? . Create a Hidden filed, then use JS to fill that value ??

    Jay


    <body>
        @using (Html.BeginForm("Index", "Home", FormMethod.Post))
        {
            @Html.HiddenFor(m => m.Date)
     
            @(Html.Kendo().Calendar()
                      .Name("calendar")
                      .Value(DateTime.Now)
                      )
            <button name="button" value="save">Save Date</button>
        }
     
        <script>
            $(document).ready(function () {
                var calendar = $("#calendar").data("kendoCalendar");
                calendar.bind("change", function (e) {
                    $("#Date").val(this.value());
                });
            });
        </script>
    </body>
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 19 Mar 2013 Link to this post

    Hello Jay,

    As I replied in the other forum thread that you opened - this is the preffered way to do it. The calendar is not intended to be submitted to the server - so consider using the DatePicker widgets.

    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!
Back to Top