2016-12-02 707 views
0

我不知道如何调试此错误。jQuery.Deferred异常:无法读取未定义的属性“模型”

我有一个kendo网格,允许用户通过拖放来对行进行排序,并且还允许用户更新这些行中的单元格。添加排序功能后,但是我在尝试更新行时此错误:

jQuery.Deferred exception: Cannot read property 'models' of undefined  TypeError: Cannot read property 'models' of undefined 

我有这样的代码:

@(Html.Kendo().Grid<DocumentProperties>(Model.CurrentList) 
     .Name("Grid") 
     .Columns(columns => 
     { 
      columns.Bound(p => p.ID).Visible(false); 
      columns.Bound(p => p.SortOrder).Visible(false); 
      columns.Bound(p => p.DisplayText).Title("Title"); 
      columns.Bound(p => p.FileName).Title("File Name"); 
      columns.Bound(p => p.ID).ClientTemplate(@Html.ActionLink("View", "ViewDocument", new { id = "did" }, new { target = "_blank" }).ToHtmlString().Replace("did", "#: ID #")).Title("").Width(80); //creates link to view the uploaded document 
      columns.Bound(p => p.ID).ClientTemplate(@Html.ActionLink("Remove", "DeleteDocument", new { id = "did" }, new { onclick = "return confirm('Are you sure you want to delete this document?');", style = "color:Red;" }).ToHtmlString().Replace("did", "#: ID #")).Title("").Width(80); 
      columns.Command(commands => 
      { 
       commands.Edit(); // The "edit" command will edit and update data items. 

      }).Title("").Width(80); 
     }) 

     .DataSource(dataSource => dataSource 
      .Ajax() 
       .Update(update => update.Action("DocAttributeUpdate", "Blurb")) // Action invoked when the user saves an updated data item. 
       .Events(events => events.Error("error_handler")) 
       .PageSize(20) 
       .ServerOperation(false) 

       .Model(model => 
       { 
        model.Id(p => p.ID); // Specify the property which is the unique identifier of the model. 
        model.Field(p => p.ID).Editable(false); // Make the ID property not editable. 
        model.Field(p => p.SortOrder).Editable(false); // Make the SortOrder property not editable. 
        model.Field(p => p.FileName).Editable(false); // Make the FileName property not editable. 
        model.Field(p => p.DisplayText).Editable(true); // Make the DisplayText property editable. 
       }) 

      ) 
     .Sortable(sortable => sortable 
      .Enabled(true) 
      ) 
     .Pageable(pageable => pageable 
     //.Refresh(true) Need to figure this out. Doesn't refresh properly. 
       .PageSizes(true) 
       .ButtonCount(5)) 

      .Resizable(r => r.Columns(true))    

     .Selectable(selectable => selectable.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row)) //make each row selectable 

     ) 

     @(Html.Kendo().Sortable() //this adds the cool drag and drop sorting 
       .For("#Grid") 
        .Filter("table > tbody > tr") 
        .Cursor("move") 
        .HintHandler("noHint") 
        .PlaceholderHandler("placeholder") 
        .ContainerSelector("#Grid tbody") 
        .Events(events => events.Change("onChange")) 

      ) 

     <script type="text/javascript"> 
     var noHint = $.noop; 

     function placeholder(element) { 
      return element.clone().addClass("k-state-hover").css("opacity", 0.65); 
     } 

     function onChange(e) { 
      var grid = $("#Grid").data("kendoGrid"), 
      skip = grid.dataSource.skip(), 
      oldIndex = e.oldIndex + skip, 
      newIndex = e.newIndex + skip, 
      dataItems = grid.dataSource.data(), 
      dataItem = grid.dataSource.getByUid(e.item.data("uid")); //grab your item and give it a new index. Then remove the item from the list and place in the new index. 

      grid.dataSource.remove(dataItem); 
      grid.dataSource.insert(newIndex, dataItem); 

      var dataList = []; 

      for (var i = 0; i < dataItems.length; i++) { 

       dataList[i] = { 
        ID: dataItems[i].ID, 
        ClientId: dataItems[i].ClientId, 
        SortOrder: i, 
        DisplayText: dataItems[i].DisplayText, 
        Type: dataItems[i].Type, 
        MimeType: dataItems[i].MimeType, 
        FileName: dataItems[i].FileName 

       }; 

      } 

      $.ajax({ 
       url: "/Blurb/SaveSortOrder", 
       type: "POST", 
       data: { 
        data: JSON.stringify(dataList) //send our json string back to the server for sorting 
       } 

      }) 
     }; 

当我删除代码:

@(Html.Kendo().Sortable() 

更新按钮再次工作,但我没有我的拖放排序了。

jQuery脚本:

<script> 
          jQuery(function() { 
           jQuery("#Grid").kendoGrid({ 
            "columns": [{ 
             "title": "Title", 
             "headerAttributes": { 
              "data-field": "DisplayText", 
              "data-title": "Title" 
             }, 
             "field": "DisplayText", 
             "encoded": true, 
             "editor": "\u003cinput class=\"text-box single-line\" id=\"DisplayText\" name=\"DisplayText\" type=\"text\" value=\"\" /\u003e\u003cspan class=\"field-validation-valid\" data-valmsg-for=\"DisplayText\" data-valmsg-replace=\"true\"\u003e\u003c/span\u003e" 
            }, { 
             "title": "File Name", 
             "headerAttributes": { 
              "data-field": "FileName", 
              "data-title": "File Name" 
             }, 
             "field": "FileName", 
             "encoded": true 
            }, { 
             "headerAttributes": { 
              "data-field": "ID", 
              "data-title": "" 
             }, 
             "width": "80px", 
             "template": "\u003ca href=\"/Blurb/ViewDocument/#: ID #\" target=\"_blank\"\u003eView\u003c/a\u003e", 
             "field": "ID", 
             "encoded": true 
            }, { 
             "headerAttributes": { 
              "data-field": "ID", 
              "data-title": "" 
             }, 
             "width": "80px", 
             "template": "\u003ca href=\"/Blurb/DeleteDocument/#: ID #\" onclick=\"return confirm(\u0027Are you sure you want to delete this document?\u0027);\" style=\"color:Red;\"\u003eRemove\u003c/a\u003e", 
             "field": "ID", 
             "encoded": true 
            }, { 
             "width": "80px", 
             "command": [{ 
              "name": "edit", 
              "buttonType": "ImageAndText", 
              "text": "Edit" 
             }] 
            }], 
            "pageable": { 
             "pageSizes": [5, 10, 20], 
             "buttonCount": 5 
            }, 
            "sortable": true, 
            "selectable": "Single, Cell", 
            "resizable": true, 
            "scrollable": false, 
            "editable": { 
             "confirmation": "Are you sure you want to delete this record?", 
             "confirmDelete": "Delete", 
             "cancelDelete": "Cancel", 
             "mode": "inline", 
             "create": true, 
             "update": true, 
             "destroy": true 
            }, 
            "messages": { 
             "noRecords": "No records available." 
            }, 
            "dataSource": { 
             "type": (function() { 
              if (kendo.data.transports['aspnetmvc-ajax']) { 
               return 'aspnetmvc-ajax'; 
              } else { 
               throw new Error('The kendo.aspnetmvc.min.js script is not included.'); 
              } 
             })(), 
             "transport": { 
              "read": { 
               "url": "" 
              }, 
              "prefix": "", 
              "update": { 
               "url": "/Blurb/DocAttributeUpdate" 
              } 
             }, 
             "pageSize": 20, 
             "page": 1, 
             "total": 3, 
             "error": error_handler, 
             "schema": { 
              "data": "Data", 
              "total": "Total", 
              "errors": "Errors", 
              "model": { 
               "id": "ID", 
               "fields": { 
                "ID": { 
                 "editable": false, 
                 "type": "number" 
                }, 
                "ClientId": { 
                 "type": "number" 
                }, 
                "SortOrder": { 
                 "editable": false, 
                 "type": "number", 
                 "defaultValue": null 
                }, 
                "DisplayText": { 
                 "type": "string" 
                }, 
                "Type": { 
                 "type": "string" 
                }, 
                "MimeType": { 
                 "type": "string" 
                }, 
                "FileName": { 
                 "editable": false, 
                 "type": "string" 
                }, 
                "Document": { 
                 "type": "object" 
                } 
               } 
              } 
             }, 
             "data": { 
              "Data": [{ 
               "ID": 440, 
               "ClientId": 16, 
               "DisplayText": "Test Document", 
               "FileName": "3182AscensionRecipientsDashboard (5).pdf", 
               "Type": "Document", 
               "MimeType": "application/pdf", 
               "Document": { 
                "ID": 0, 
                "DocumentAttributeId": 0, 
                "FileContent": null , 
                "Content": null 
               }, 
               "SortOrder": 0 
              }, { 
               "ID": 5, 
               "ClientId": 16, 
               "DisplayText": "Summary Plan Description", 
               "FileName": "Summary Plan Description.pdf", 
               "Type": "Document", 
               "MimeType": "application/pdf", 
               "Document": { 
                "ID": 0, 
                "DocumentAttributeId": 0, 
                "FileContent": null , 
                "Content": null 
               }, 
               "SortOrder": 1 
              }, { 
               "ID": 6, 
               "ClientId": 16, 
               "DisplayText": "Summary Annual Report", 
               "FileName": "SUMMARY ANNUAL REPORT.pdf", 
               "Type": "Document", 
               "MimeType": "application/pdf", 
               "Document": { 
                "ID": 0, 
                "DocumentAttributeId": 0, 
                "FileContent": null , 
                "Content": null 
               }, 
               "SortOrder": 2 
              }], 
              "Total": 3, 
              "AggregateResults": null 
             } 
            } 
           }); 
          }); 
         </script> 
+0

你能发布这类呈现为kendo.mvc语法的结果jQuery脚本..你可以查看页面的源代码,并把它 –

+0

@Reddy我编辑了我的文章,包括脚本。 – SimplyZ

回答

0

我不得不方法进行编辑,有点不同,以得到这个工作,但我还是可以尝试找出为什么我原来的办法是行不通的。 我不得不添加剑道的工具栏功能,使细胞编辑:

.ToolBar(toolBar => 
    { 
     toolBar.Save(); 

    }) 
.Editable(editable => editable.Mode(GridEditMode.InCell)) 
相关问题