e.slice不是带有Kendo UI的ASP.NET MVC中的函数错误 [英] e.slice is not a function error in ASP.NET MVC with Kendo UI

查看:151
本文介绍了e.slice不是带有Kendo UI的ASP.NET MVC中的函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on asp.net MVC with Kendo UI grid. I am getting the information from a method and give it to the grid. and I have in toolbar a datepicker so when I pick a new date the code will go to the method refilter the LINQ then I received a new list.

我写了这段代码:

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:

and here is the javascript when I change the datepicker:

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")
                        }
                    }
                }
            }
        });
}

一切正确,我可以正确访问该方法.但是在过滤器之后返回方法后,我收到并出错:

everything is correct and I can access the method correctly. but after the return of the method after the filter I receive and error:

kendo.all.js:6599未捕获的TypeError:e.slice不是函数

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

我不知道为什么以及如何解决它.请帮忙吗?

I don't know why and how to solve it. please if you can help me with it?

推荐答案

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

As you are use the kendo ui MVC grid so i would suggest that go with below method.

查看

@(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不是函数"的根本原因是,我们没有将数组绑定到kendo网格,而是绑定了对象. (因为我们只能应用切片方法数组)

The root cause of the error "e.slice is not a function" is that instead of binding array to the kendo grid we binding object. (because we can apply slice method array only)

这篇关于e.slice不是带有Kendo UI的ASP.NET MVC中的函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆