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

Passing selected row values to controller

1 Answer 511 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tomás
Top achievements
Rank 1
Tomás asked on 03 Jul 2014, 11:28 AM
Hi,

I've got an image and a kendo grid:

        <a href="#" id="ic_open" class="tooltip2" title="Abrir">
            <span title="">
                <img class="toolbar-icons" src="../../Images/open.png"/>
            </span>
        </a>
...
 
    <div id="datagrid">
        @(Html.Kendo().Grid(Model)
            .Name("datagrid_Concessoes")
            .Columns(columns =>
            {
                columns.Bound(c => c.Id).Width(70);
                columns.Bound(c => c.Code);
                columns.Bound(c => c.Description);
                columns.Bound(c => c.CreationDate);
                columns.Bound(c => c.CreationUser);
            })
            .HtmlAttributes(new { style = "height: 534px;" })
            .Scrollable()
            .Sortable()
            .Selectable()
            .Pageable(pageable => pageable
                .Refresh(true)
                .ButtonCount(5))
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(15)
                .Read(read => read.Action("GetConcessoes", "MasterData"))
            )
        )
    </div>

I've got this script too:

<script type="text/javascript">
 
$(function () {
    $('.tooltip2').click(function () {
 
            var id = this.id;
 
            $.get('@Url.Content("GetPartialView")',
            { "id": id },
            function (data) {
                $('#div-for-partial').html(data);
            });
 
        });
    });
 
</script>

...which passes the element id to the controller.

I want to pass the selected row values to the controller so I can manipulate that information.

Thanks

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Jul 2014, 08:39 AM
Hello,

You can use the select method to get the selected row and the dataItem method to get the data for the row. Sending the data to the server should be similar to the code demonstrated in the snippet below:
$('.tooltip2').click(function () {
        var grid = $("#datagrid_Concessoes").data("kendoGrid");
        var selectedItem = grid.dataItem(grid.select());
        var data = selectedItem ? selectedItem.toJSON() : {};
         
        data.id = this.id;
 
        $.get('@Url.Content("GetPartialView")',
        data,
        function (data) {
            $('#div-for-partial').html(data);
        });
 
    });
});


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Tomás
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or