e.slice is not a function error in ASP.NET MVC with Kendo UI

淺唱寂寞╮ 提交于 2019-12-10 23:59:20

问题


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.

I wrote this code:

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;

        }

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 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?


回答1:


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

View

@(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>

Controller

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

Modal

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

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)



来源:https://stackoverflow.com/questions/39996897/e-slice-is-not-a-function-error-in-asp-net-mvc-with-kendo-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!