Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery MVC剑道网格-未捕获类型错误:无法读取属性';id';未定义的_Jquery_Model View Controller_Model_Kendo Ui_Grid - Fatal编程技术网

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);
}