0
votes

I have a Kendo Grid and template column

columns.Template(t => t.id)
    .ClientTemplate("<button style='margin:2px' type='button' class='btn btn-success btn-xs' data-toggle='tooltip' data-placement='left' title='Change' onclick='getID()'><span class='glyphicon glyphicon-cog'></span></button>")
    .Width(30)
    .HtmlAttributes(new { @style = "text-align:center" });

And

function getID(e) {
    debugger;
    var grid = $("#Grid").data("kendoGrid");
    var model = model.id
    alert(model.id);
}

I'm just getting this error:

Uncaught TypeError: Cannot read property 'id' of undefined.

Why? What can I do to get a model ID where the button is clicked?

1
The logic is flawed. You're redefining model as model.id then attempting to retrieve the id property on what is now presumably a string or int.Rory McCrossan

1 Answers

0
votes

I am assuming that you are trying to access the model variable in razor in javascript and you can't do like that.

 function getID(e) {
    debugger;
    var grid = $("#Grid").data("kendoGrid");
    var dataItem= grid.dataItem(grid.select());//gets the dataItem for the current row
    alert(dataItem.id);
}