Jquery MVC剑道网格-未捕获类型错误:无法读取属性';id';未定义的
我有剑道格网和模板栏Jquery MVC剑道网格-未捕获类型错误:无法读取属性';id';未定义的,jquery,model-view-controller,model,kendo-ui,grid,Jquery,Model View Controller,Model,Kendo Ui,Grid,我有剑道格网和模板栏 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 glyphi
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" });
我刚刚得到这个错误:
未捕获的TypeError:无法读取未定义的属性“id”
为什么??在单击按钮的位置,我能做些什么来获取模型ID?我假设您试图在javascript中访问razor中的模型变量,但您不能这样做
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);
}
逻辑是有缺陷的。您正在将
model
重新定义为model.id
,然后尝试检索现在可能是字符串或int的id
属性。
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);
}