【问题标题】:e.slice is not a function error in ASP.NET MVC with Kendo UIe.slice 不是带有 Kendo UI 的 ASP.NET MVC 中的函数错误
【发布时间】:2017-02-21 03:43:03
【问题描述】:

我正在开发带有 Kendo UI 网格的 asp.net MVC。 我从一种方法中获取信息并将其提供给网格。我在工具栏中有一个日期选择器,所以当我选择一个新日期时,代码将转到重新过滤 LINQ 的方法,然后我收到一个新列表。

我写了这段代码:

public ActionResult Grid_ReadLogAdminList([DataSourceRequest] DataSourceRequest request,[Bind(Prefix = "id")] string date)
        {

//both the date and  result is correct always
            var jsonResult = Json(result, JsonRequestBehavior.AllowGet);
            jsonResult.MaxJsonLength = int.MaxValue;
            return jsonResult;

        }

这是我更改日期选择器时的 javascript:

function filterDate()
    {
$("#LogAdminGrid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: '/LogAdmin/Grid_ReadLogAdminList/',
                        type: 'get',
                        dataType: 'json',
                        data: {
                            id: kendo.toString($("#datepicker").data("kendoDatePicker").value(), "dd.MM.yyyy")
                        }
                    }
                }
            }
        });
}

一切都正确,我可以正确访问该方法。但是在过滤器后返回方法后我收到错误:

kendo.all.js:6599 Uncaught TypeError: e.slice is not a function

我不知道为什么以及如何解决它。请问你能帮我吗?

【问题讨论】:

  • 发布包含该 e.slice 或完整错误的代码
  • 这是完整的错误,代码来自 Kendo.all 库我没有使用这个函数也没有写它
  • 结果对象是什么?如果它是一些描述的集合,您是否确保将其返回为 .ToDataSourceResult() 实际返回到网格的东西是什么?
  • 数据没问题,网格没问题。因为我已经写好了
  • 这个错误总是与“未定义”的东西有关,我可以告诉你。

标签: kendo-ui telerik kendo-grid kendo-asp.net-mvc telerik-grid


【解决方案1】:

由于您使用的是 kendo ui MVC 网格,所以我建议您使用以下方法。

查看

@(Html.Kendo().Grid<WebApplication2.Models.Product>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(product => product.ProductID);
                columns.Bound(product => product.ProductName);
            })
            .Pageable()
            .Sortable()
            .DataSource(dataSource => dataSource
                            .Ajax()
                            .Model(model =>
                            {
                                model.Id(x => x.ProductID);
                            })
                            .Read(read => read.Action("Grid_Read", "Home").Data("gridParam"))
             )
)

<input id="txtID" type="text" value="1" />
<input type="button" value="filterGrid" onclick="filterGrid();" />

<script>
    function gridParam() {
        return {
            ID: $("#txtID").val()
        }
    }
    function filterGrid() {
        $("#grid").data("kendoGrid").dataSource.read();
        $("#grid").data("kendoGrid").refresh();
    }

</script>

控制器

public ActionResult Grid_Read([DataSourceRequest]DataSourceRequest request, int? ID)
{
    List<Product> lst = new List<Product>();
    lst.Add(new Product() { ProductID = 1, ProductName = "aaa" });
    lst.Add(new Product() { ProductID = 2, ProductName = "bbb" });
    lst.Add(new Product() { ProductID = 3, ProductName = "ccc" });
    if (ID.HasValue)
        lst = lst.Where(i => i.ProductID == ID.GetValueOrDefault()).ToList();
    return Json(lst.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

模态

 public class Product
    {
        public int ProductID { get; set; }
        public string ProductName { get; set; }
    }

错误“e.slice is not a function”的根本原因是我们绑定对象而不是绑定数组到剑道网格。 (因为我们只能应用切片方法数组)

【讨论】:

  • 太棒了,我花了两天时间。但我找不到解决方案。我猜问题是通过错误的方式传递参数
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 1970-01-01
  • 2021-02-17
相关资源
最近更新 更多