Grid MVC checkbox not returning value to controller method

4 posts, 0 answers
  1. Randy
    Randy avatar
    75 posts
    Member since:
    Jul 2009

    Posted 11 May 2017 Link to this post

    I'm using an MVC grid on a page which contains a checkbox column. It's defined as follows:

            columns.Bound(p => p.IsActive).Title("Active?").ClientTemplate("<input type='checkbox' #= IsActive ? checked='checked' : '' # />").Width(80);

    I have JavaScript code that captures a change in the value of the checkbox and sets the underlying data item to true or false as follows:

    $("#grid .k-grid-content").on("change", "input#IsActive", function (e) {
            var grid = $("#grid").data("kendoGrid");
            var checked = $(this).is(':checked');
            var col = $(this).closest('td');
            dataItem = grid.dataItem($(e.target).closest("tr"));
            dataItem.set(grid.columns[col.index()].field, checked);
        });

    All this works exactly as it should. Except when the user saves the row and my controller Update method is called, the value of the checkbox is always returned as false, even if the checkbox is checked. I have verified that the value of 'checked' above is true and the underlying data item is being set to true. But a false is always returned to the controller method.

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 15 May 2017 Link to this post

    Hello,

    I just tested the Checkboxes batch editing how-to article and it works fine. The check box value is property sent to the server after a change. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Randy
    Randy avatar
    75 posts
    Member since:
    Jul 2009

    Posted 15 May 2017 in reply to Boyan Dimitrov Link to this post

    Boyan - Thanks for the response. In order to save me some time, do you see anything wrong with my code? The code essentially works, I'm just not getting the status of the check box returned to my controller method.
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 16 May 2017 Link to this post

    Hello Randy,

    Everything with the code seems fine. It is sent the modified data item to the update action. Since the data item is property updated with the check box value it should be sent as expected. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top