我正在使用 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
我不知道为什么以及如何解决它。请问您能帮我吗?
最佳答案
由于您使用的是 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>
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);
}
模态
public class Product
{
public int ProductID { get; set; }
public string ProductName { get; set; }
}
错误“e.slice不是函数”的根本原因是我们没有将数组绑定(bind)到剑道网格,而是绑定(bind)了对象。 (因为我们只能应用切片方法数组)
关于kendo-ui - e.slice 不是带有 Kendo UI 的 ASP.NET MVC 中的函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39996897/