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

1

2

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?

Gastight answered 12/10, 2016 at 10:59 Comment(5)
post the code that contains that e.slice or the full errorDermatophyte
this is the full error and the code came from Kendo.all Library I did not use this funtion nor wrote itGastight
what is the result object? If it is a collection of some description have you ensured you are returning this back as a .ToDataSourceResult() what is the thing that is actually returned back to grid?Electromechanical
the data is okat and the grid is okay. because I already write itGastight
That error is always tied to something being 'undefined' that much I can tell you.Evaevacuant
P
2

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)

Pupiparous answered 12/10, 2016 at 18:49 Comment(2)
Awesome, I spend two days on this. but I couldn't find the solution. I guess the problem was by passing the parameter in a wrong wayGastight
I appreciate this solution. I've been looking for days to find a solid way to pass a parameter outside of the grid and this is the first time I've seen the .Data from the .read in the Datasource and a well laid out example to boot. Thanks.Wilmoth

© 2022 - 2024 — McMap. All rights reserved.