ReferenceError: Id is not defined in /Directory/Users
1 Answer, 1 is accepted
0
Mihaela
Telerik team
answered on 09 Aug 2023, 02:47 PM
Hello,
By desing, the underlying data item cannot be accessed in the column commands. However, I would suggest the following approach:
Attach the "onclick" event to the anchor tag and disable the "href" attribute.
Get a reference to the Grid and call the dataItem() method to access the respective data item.
Use the "location.href" property to redirect the user to the appropriate URL.
columns.Command(c => c.Custom("Page").Template("<a href='javascript:;' onclick='getUserPage(event);'>Page</a>"));
<scripttype="text/javascript">functiongetUserPage(e) {
var grid = $("#grid").getKendoGrid(); //get the Grid instancevar dataItem = grid.dataItem($(e.currentTarget).closest("tr")); //get the data item
location.href = "/Directory/User/" + dataItem.Id;
}
</script>
I hope that helps.
Regards,
Mihaela
Progress Telerik
Stay tuned by visiting our public roadmap and feedback portalpages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.