This is a migrated thread and some comments may be shown as answers.

Grid MVC checkbox not returning value to controller method

3 Answers 403 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 12 May 2017, 01:04 AM

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.

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 15 May 2017, 01:12 PM

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.
0
Randy
Top achievements
Rank 1
answered on 15 May 2017, 01:14 PM
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.
0
Boyan Dimitrov
Telerik team
answered on 16 May 2017, 12:48 PM

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.
Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Randy
Top achievements
Rank 1
Share this question
or