This is a migrated thread and some comments may be shown as answers.

Can't get kendo grid to work in MVC without MVC wrapper

1 Answer 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BRAD
Top achievements
Rank 1
BRAD asked on 21 Mar 2015, 01:56 PM
I'm building a 'sample' project in asp.net MVC for my clients to show them how to interface with our services, and i'm using kendo core which means no MVC wrappers.  Basically i have the javascript:
function loadAttGrid() {
            var attgeturl = "@Url.Action("_GetAttachmentListJSON", "Attachment", new { area = "MVCPlug", id = ViewContext.RouteData.Values["id"] }, null)";
            var attupdateurl = "@Url.Action("_UpdateAttachment", "Attachment", new { area = "MVCPlug", id = ViewContext.RouteData.Values["id"] }, null)";
            var attdeleteurl = "@Url.Action("_DeleteLogEntry", "Attachment", new { area = "MVCPlug", id = ViewContext.RouteData.Values["id"] }, null)";
            $("#attgrid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: attgeturl,
                            type: "GET",
                            dataType:"json"
                        },
                        update: {
                            url: attupdateurl,
                            type: "POST",
                            dataType: "json"
                        },
                        destroy: {
                            url: attdeleteurl,
                            type: "POST",
                            dataType: "json"
                        }
                    },
                    parameterMap: function (options, operation) {
                        if (operation !== "read" && options.models) {
                            return { models: kendo.stringify(options.models) };
                        }
                    },
                    pageSize: 10,
                    schema: {
                        model: {
                            id: "LogEntryGUID",
                            fields: {
                                LogEntryGUID: { editable: false },
                                FileName: { editable: false },
                                FriendlyUserName: { editable: false },
                                LocationString: { editable: false },
                                EventDescription: { editable: true },
                                FormattedDateCreated: { type: "date", editable: false }
                            }
                        }
                    }
                },
                selectable: false,
                sortable: true,
                filterable: true,
                editable: "inline",
                pageable: {
                    refresh: false,
                    pageSizes: false,
                    buttonCount: 5
                },
                columns: [
                  { field: 'FileName', title: 'File Name' },
                  { field: 'FriendlyUserName', title: 'User' },
                  { field: 'EventDescription', title: 'Description' },
                  { field: 'FormattedDateCreated', title: 'Date Created', format: "{0:G}" },
                  {
                      command: [
                          //define the commands here
                          { name: "edit", text: " " },
                          { name: "destroy", text: " " }
                      ],
                      title: " ", width: "85px"
                  }
                ]
            });
        }
which works fine when using MVC wrappers, and the 'read' url for the controller looks like 
public ActionResult _GetAttachmentListJSON([DataSourceRequest] DataSourceRequest, Guid id)
        {
            Models.ArrayOfFullLogEntry theAtts = null;
            if (id != Guid.Empty)
            {
                theAtts = GetAttList(id);
            }
            return Json(theAtts.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
but it does NOT work if i change the controller to not use the wrapper, like:
public ActionResult _GetAttachmentListJSON(Guid id)
        {
            Models.ArrayOfFullLogEntry theAtts = null;
            if (id != Guid.Empty)
            {
                theAtts = GetAttList(id);
            }
            return Json(theAtts, JsonRequestBehavior.AllowGet);
        }
what do i need to change in the javascript to make this wrapper-less controller work?

1 Answer, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 30 Aug 2016, 06:04 PM

I'm having the same exact problem. All I get back is JSON in my browser and nothing else. I copied/pasted a basic example with local data just to make sure the grid would render - and it did. But it doesn't work when wiring it up to my controller returning JSON.

Can someone answer this please?

Tags
Grid
Asked by
BRAD
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Share this question
or