I have a KendoUI grid which is getting data from an ASP.NET MVC application. The grid populates itself fine but I'm having problems with the create function.
The data is correctly sent to the controller action and the object persisted to the database but I'm unsure as to what I'm supposed to return. Currently I'm returning the object but I'm getting a Javascript error on the client "Uncaught TypeError: Cannot read property 'length' of undefined". The result is the new entry in the grid remains with a "null" Id value and the Name field has a red triangle on the top-left corner.
Controller Action:
Grid configuration:
The data is correctly sent to the controller action and the object persisted to the database but I'm unsure as to what I'm supposed to return. Currently I'm returning the object but I'm getting a Javascript error on the client "Uncaught TypeError: Cannot read property 'length' of undefined". The result is the new entry in the grid remains with a "null" Id value and the Name field has a red triangle on the top-left corner.
Controller Action:
[HttpPost]public JsonResult Create(Department dept){ _session.Store(dept); _session.SaveChanges(); return Json(dept);}Grid configuration:
$(document).ready(function () { $("#grid").kendoGrid({ dataSource: { type: "json", serverPaging: true, pageSize: 10, batch: false, transport: { read: { url: "Departments/GetAll", dataType: "json" }, create: { url: "Departments/Create", type: "post", dataType: "json" } }, schema: { data: "Departments", total: "TotalCount", model: { id: "Id", fields: { Id: { type: "number", editable: false, nullable: true }, Name: { editable: true, nullable: false, validation: { required: true } } } } } }, height: 400, toolbar: ["create"], pageable: true, columns: [ { field: "Id", title: "Dept Id" }, { field: "Name", title: "Name" } ], editable: { mode: "popup", update: false, destroy: false } });});