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

2 posts, 0 answers
  1. BRAD
    BRAD avatar
    27 posts
    Member since:
    May 2012

    Posted 21 Mar 2015 Link to this post

    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?
  2. Mark
    Mark avatar
    1 posts
    Member since:
    Aug 2016

    Posted 30 Aug 2016 in reply to BRAD Link to this post

    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?

Back to Top