This is what I am returning as ActionResult from the Controller:
// oCats is List of Category objects so derives from IEnumerable
var vResult = oCats.ToDataSourceResult(request);
var x = Json(vResult, JsonRequestBehavior.AllowGet);
return (x);
When I mouse over the breakpoint on the last line, I have all forty Categories properly . . . but when the View tries to load I get this:
"Unhandled exception at line 190, column 1 in Function code
0x800a138f - Microsoft JScript runtime error: Unable to get value of the property '__count': object is null or undefined"
in the Function js file and it crashes. Ideas for solution?
Thanks
// oCats is List of Category objects so derives from IEnumerable
var vResult = oCats.ToDataSourceResult(request);
var x = Json(vResult, JsonRequestBehavior.AllowGet);
return (x);
When I mouse over the breakpoint on the last line, I have all forty Categories properly . . . but when the View tries to load I get this:
"Unhandled exception at line 190, column 1 in Function code
0x800a138f - Microsoft JScript runtime error: Unable to get value of the property '__count': object is null or undefined"
in the Function js file and it crashes. Ideas for solution?
Thanks
4 Answers, 1 is accepted
0
David
Top achievements
Rank 1
answered on 03 Mar 2013, 07:43 AM
Scary, this went away in Firefox. And Chrome. Still happens in IE.
0
Hello David,
Daniel
the Telerik team
I am not sure what is causing the problem. The parameter from the error message should be used only with type "odata" and from the snippet you provided it seems that you are using the MVC wrappers. Could you provide the full code you are using so I can check the setup?
Regards,Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
David
Top achievements
Rank 1
answered on 04 Mar 2013, 05:24 PM
Sorry, thought I did. I really appreciate the help.
From the Controller on out:
CONTROLLER:
public ActionResult MasterCategories_Read([DataSourceRequest] DataSourceRequest request)
{
List<BusinessClassLibrary.MasterCategory> oCats = new List<BusinessClassLibrary.MasterCategory>();
var service = new MasterCategoryService("");
var oCategories = service.GetAll();
foreach (BusinessClassLibrary.MasterCategory oCategory in oCategories)
{
oCats.Add(oCategory);
}
var vResult = oCats.ToDataSourceResult(request);
var x = Json(vResult, JsonRequestBehavior.AllowGet);
return (x);
}
VIEW MODEL:
var oRemoteDataSource;
$(document).ready(function () {
InitGrid();
InitDataSource();
oRemoteDataSource.read();
});
function InitGrid() {
$("#grid").kendoGrid({
dataSource: oRemoteDataSource,
edit: EditMe,
save: SaveMe,
create: function(){
alert("create");
},
sortable: true,
selectable: "row",
id: "Code",
error: function (e) {
alert(e.responseText);
},
editable: {
update: true, // puts the row in edit mode when it is clicked
destroy: false, // does not remove the row when it is deleted, but marks it for deletion
confirmation: "Are you sure you want to remove this category?"
},
pageable: {
numeric: true,
refresh: true,
pageSizes: [3, 6, 10],
previousNext: true,
input: false,
info: false
},
schema: {
model: {
id: "Code",
fields: {
"Name": { editable: false },
"Code": { nullable: true },
"IsPrecontract": { editable: false },
"IsActive": { editable: false }
}
}
},
columns: [
{ field: "Name", title: "Name", width: "450px" },
{ field: "Code", title: "Code", width: "40px", editable: false },
{ field: "IsPrecontract", title: "IsPrecontract", width: "80px" },
{ field: "IsActive", title: "IsActive", width: "80px" },
{ command: ["destroy"], title: " ", width: "80px" }
],
toolbar: [
"create",
{ name: "save", text: "Save This Record" }
],
});
}
function InitDataSource() {
oRemoteDataSource = new kendo.data.DataSource({
type: "odata",
pageSize: 10,
transport: {
read: function (options) {
$.ajax({
url: "/KendoGrid/MasterCategories_Read",
data: options.data, // the "data" field contains paging, sorting, filtering and grouping data
success: function (result) {
// alert(JSON.stringify(result));
$("#json").html(JSON.stringify(result));
options.success(result);
}
});
},
update: {
url: "/KendoGrid/MasterCategories_Update",
type: "POST"
}
}
});
}
function EditMe() {
// alert("edit");
var grid = $("#grid").data("kendoGrid");
var selectedItem = grid.dataItem(grid.select());
// alert(selectedItem.id);
arrEditIDs[arrEditIDs.length] = selectedItem.id;
}
function SaveMe() {
var grid = $("#grid").data("kendoGrid");
$.each(data, function (i, item) {
for (x = 0; x < arrEditIDs.length; x++) {
if (arrEditIDs[x] == item.id) {
alert("Saving changes to: " + item.id + " | " + item.title);
}
}
});
}
VIEW:
@{
ViewBag.Title = "MasterCatGridKendo";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@model IEnumerable<BchPro.Models.MasterCategoryModel>
@using Kendo.Mvc.UI
<script src="http://localhost:5328/ViewModels/MasterCatGridKendoViewModel.js"></script>
<table id="grid"></table>
<div id="json" />
<script src="http://localhost:5328/Scripts/kendo/2012.3.1315/kendo.all.min.js"></script>
<script src="http://localhost:5328/Scripts/kendo/2012.3.1315/kendo.aspnetmvc.min.js"></script>
When I run this all together as is, I get this JSON in the div mentioned above but nothing in the grid:
{"Data":[{"Name":"Hardwood Stairs","Code":"39","IsPrecontract":"N","IsActive":"Y"},{"Name":"Siding","Code":"10","IsPrecontract":"N","IsActive":"Y"},{"Name":"Fireplace","Code":"26","IsPrecontract":"N","IsActive":"Y"},{"Name":"Stair Railing","Code":"40","IsPrecontract":"N","IsActive":"Y"},{"Name":"Tile Accessories","Code":"25","IsPrecontract":"N","IsActive":"Y"},{"Name":"Interior Doors","Code":"36","IsPrecontract":"N","IsActive":"Y"},{"Name":"Hardware & Mirrors","Code":"31","IsPrecontract":"N","IsActive":"Y"},{"Name":"Permit, Fees and Insurance","Code":"01","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Job Clean-up","Code":"34","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Deck","Code":"12","IsPrecontract":"N","IsActive":"Y"},{"Name":"Countertops","Code":"29","IsPrecontract":"N","IsActive":"Y"},{"Name":"Rain Gutters","Code":"32","IsPrecontract":"N","IsActive":"Y"},{"Name":"Light Fixtures","Code":"20","IsPrecontract":"N","IsActive":"Y"},{"Name":"Entry Doors","Code":"13","IsPrecontract":"N","IsActive":"Y"},{"Name":"Damp Proofing","Code":"07","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Electrical","Code":"19","IsPrecontract":"N","IsActive":"Y"},{"Name":"Temporary Utilities","Code":"04","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Architecture & Engineering","Code":"03","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Paint","Code":"24","IsPrecontract":"N","IsActive":"Y"},{"Name":"Speciality Items","Code":"80","IsPrecontract":"N","IsActive":"Y"},{"Name":"Windows","Code":"15","IsPrecontract":"N","IsActive":"Y"},{"Name":"Drywall","Code":"22","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Electrical Features - Upgrade","Code":"42","IsPrecontract":"N","IsActive":"Y"},{"Name":"Garage Doors","Code":"14","IsPrecontract":"N","IsActive":"Y"},{"Name":"Foundation","Code":"06","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Insulation","Code":"21","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Cabinets","Code":"28","IsPrecontract":"N","IsActive":"Y"},{"Name":"Stone","Code":"23","IsPrecontract":"N","IsActive":"Y"},{"Name":"Trim Materials","Code":"37","IsPrecontract":"N","IsActive":"Y"},{"Name":"Design Ideas","Code":"00","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Appliances","Code":"30","IsPrecontract":"N","IsActive":"Y"},{"Name":"Central Vacuum","Code":"33","IsPrecontract":"N","IsActive":"Y"},{"Name":"Roofing","Code":"11","IsPrecontract":"N","IsActive":"Y"},{"Name":"Framing","Code":"08","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Lot Improvements","Code":"02","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Air Conditioning","Code":"18","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Heating and Ventilation","Code":"17","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Plumbing","Code":"16","IsPrecontract":"N","IsActive":"Y"},{"Name":"Closet Shelving","Code":"38","IsPrecontract":"N","IsActive":"Y"},{"Name":"Flooring","Code":"27","IsPrecontract":"N","IsActive":"Y"}],"Total":40,"AggregateResults":null,"Errors":null}
From the Controller on out:
CONTROLLER:
public ActionResult MasterCategories_Read([DataSourceRequest] DataSourceRequest request)
{
List<BusinessClassLibrary.MasterCategory> oCats = new List<BusinessClassLibrary.MasterCategory>();
var service = new MasterCategoryService("");
var oCategories = service.GetAll();
foreach (BusinessClassLibrary.MasterCategory oCategory in oCategories)
{
oCats.Add(oCategory);
}
var vResult = oCats.ToDataSourceResult(request);
var x = Json(vResult, JsonRequestBehavior.AllowGet);
return (x);
}
VIEW MODEL:
var oRemoteDataSource;
$(document).ready(function () {
InitGrid();
InitDataSource();
oRemoteDataSource.read();
});
function InitGrid() {
$("#grid").kendoGrid({
dataSource: oRemoteDataSource,
edit: EditMe,
save: SaveMe,
create: function(){
alert("create");
},
sortable: true,
selectable: "row",
id: "Code",
error: function (e) {
alert(e.responseText);
},
editable: {
update: true, // puts the row in edit mode when it is clicked
destroy: false, // does not remove the row when it is deleted, but marks it for deletion
confirmation: "Are you sure you want to remove this category?"
},
pageable: {
numeric: true,
refresh: true,
pageSizes: [3, 6, 10],
previousNext: true,
input: false,
info: false
},
schema: {
model: {
id: "Code",
fields: {
"Name": { editable: false },
"Code": { nullable: true },
"IsPrecontract": { editable: false },
"IsActive": { editable: false }
}
}
},
columns: [
{ field: "Name", title: "Name", width: "450px" },
{ field: "Code", title: "Code", width: "40px", editable: false },
{ field: "IsPrecontract", title: "IsPrecontract", width: "80px" },
{ field: "IsActive", title: "IsActive", width: "80px" },
{ command: ["destroy"], title: " ", width: "80px" }
],
toolbar: [
"create",
{ name: "save", text: "Save This Record" }
],
});
}
function InitDataSource() {
oRemoteDataSource = new kendo.data.DataSource({
type: "odata",
pageSize: 10,
transport: {
read: function (options) {
$.ajax({
url: "/KendoGrid/MasterCategories_Read",
data: options.data, // the "data" field contains paging, sorting, filtering and grouping data
success: function (result) {
// alert(JSON.stringify(result));
$("#json").html(JSON.stringify(result));
options.success(result);
}
});
},
update: {
url: "/KendoGrid/MasterCategories_Update",
type: "POST"
}
}
});
}
function EditMe() {
// alert("edit");
var grid = $("#grid").data("kendoGrid");
var selectedItem = grid.dataItem(grid.select());
// alert(selectedItem.id);
arrEditIDs[arrEditIDs.length] = selectedItem.id;
}
function SaveMe() {
var grid = $("#grid").data("kendoGrid");
$.each(data, function (i, item) {
for (x = 0; x < arrEditIDs.length; x++) {
if (arrEditIDs[x] == item.id) {
alert("Saving changes to: " + item.id + " | " + item.title);
}
}
});
}
VIEW:
@{
ViewBag.Title = "MasterCatGridKendo";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@model IEnumerable<BchPro.Models.MasterCategoryModel>
@using Kendo.Mvc.UI
<script src="http://localhost:5328/ViewModels/MasterCatGridKendoViewModel.js"></script>
<table id="grid"></table>
<div id="json" />
<script src="http://localhost:5328/Scripts/kendo/2012.3.1315/kendo.all.min.js"></script>
<script src="http://localhost:5328/Scripts/kendo/2012.3.1315/kendo.aspnetmvc.min.js"></script>
When I run this all together as is, I get this JSON in the div mentioned above but nothing in the grid:
{"Data":[{"Name":"Hardwood Stairs","Code":"39","IsPrecontract":"N","IsActive":"Y"},{"Name":"Siding","Code":"10","IsPrecontract":"N","IsActive":"Y"},{"Name":"Fireplace","Code":"26","IsPrecontract":"N","IsActive":"Y"},{"Name":"Stair Railing","Code":"40","IsPrecontract":"N","IsActive":"Y"},{"Name":"Tile Accessories","Code":"25","IsPrecontract":"N","IsActive":"Y"},{"Name":"Interior Doors","Code":"36","IsPrecontract":"N","IsActive":"Y"},{"Name":"Hardware & Mirrors","Code":"31","IsPrecontract":"N","IsActive":"Y"},{"Name":"Permit, Fees and Insurance","Code":"01","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Job Clean-up","Code":"34","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Deck","Code":"12","IsPrecontract":"N","IsActive":"Y"},{"Name":"Countertops","Code":"29","IsPrecontract":"N","IsActive":"Y"},{"Name":"Rain Gutters","Code":"32","IsPrecontract":"N","IsActive":"Y"},{"Name":"Light Fixtures","Code":"20","IsPrecontract":"N","IsActive":"Y"},{"Name":"Entry Doors","Code":"13","IsPrecontract":"N","IsActive":"Y"},{"Name":"Damp Proofing","Code":"07","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Electrical","Code":"19","IsPrecontract":"N","IsActive":"Y"},{"Name":"Temporary Utilities","Code":"04","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Architecture & Engineering","Code":"03","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Paint","Code":"24","IsPrecontract":"N","IsActive":"Y"},{"Name":"Speciality Items","Code":"80","IsPrecontract":"N","IsActive":"Y"},{"Name":"Windows","Code":"15","IsPrecontract":"N","IsActive":"Y"},{"Name":"Drywall","Code":"22","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Electrical Features - Upgrade","Code":"42","IsPrecontract":"N","IsActive":"Y"},{"Name":"Garage Doors","Code":"14","IsPrecontract":"N","IsActive":"Y"},{"Name":"Foundation","Code":"06","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Insulation","Code":"21","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Cabinets","Code":"28","IsPrecontract":"N","IsActive":"Y"},{"Name":"Stone","Code":"23","IsPrecontract":"N","IsActive":"Y"},{"Name":"Trim Materials","Code":"37","IsPrecontract":"N","IsActive":"Y"},{"Name":"Design Ideas","Code":"00","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Appliances","Code":"30","IsPrecontract":"N","IsActive":"Y"},{"Name":"Central Vacuum","Code":"33","IsPrecontract":"N","IsActive":"Y"},{"Name":"Roofing","Code":"11","IsPrecontract":"N","IsActive":"Y"},{"Name":"Framing","Code":"08","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Lot Improvements","Code":"02","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Air Conditioning","Code":"18","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Heating and Ventilation","Code":"17","IsPrecontract":"Y","IsActive":"Y"},{"Name":"Plumbing","Code":"16","IsPrecontract":"N","IsActive":"Y"},{"Name":"Closet Shelving","Code":"38","IsPrecontract":"N","IsActive":"Y"},{"Name":"Flooring","Code":"27","IsPrecontract":"N","IsActive":"Y"}],"Total":40,"AggregateResults":null,"Errors":null}
0
Hello David,
Nikolay Rusev
the Telerik team
As this same thread is duplicated over two other threads I will close this ticket and post the response to your question in the following forum thread: http://www.kendoui.com/forums/mvc/grid/grid-won-t-render-with-json-looking-ok.aspx
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!