我想按姓氏过滤表格,但不能工作,这是我的代码
在控制器中
public JsonResult Filtering()
{
HealthContext rc = new HealthContext();
var last = rc.Profiles.Select(lastt => new SelectListItem { Text = lastt.LastName, Value = lastt.Id.ToString() }).ToList();
return Json(last.ToList(), JsonRequestBehavior.AllowGet);
}
在视野中
<script type="text/x-kendo-template" id="template">
<div class="toolbar">
<label class="category-label" for="Last name"> by last name:</label>
<input type="search" id="LastName" style="width: 230px"></input>
</div>
</script>
并且
以下代码段用于显示表和过滤姓氏
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
transport: {
read: {
url: "/Profiles/GetJsonData",
dataType: "json"
}
},
pageSize: 10,
},
toolbar: kendo.template($("#template").html()),
height: 250,
filterable: true,
sortable: true,
pageable: true,
defaultSorting: 'LastName ASC',
columns: [{
field: "Id",
filterable: false
},
{
field: "FirstName",
title: "First Name",
width: 100,
}, {
field: "LastName",
title: "Last Name",
width: 200
}, {
field: "Gender",
title: "Gender"
}
]
});
var dropDown = grid.find("#LastName").kendoDropDownList({
dataTextField: "LastName",
dataValueField: "Id",
autoBind: false,
optionLabel: "All",
dataSource: {
severFiltering: true,
transport: {
read: {
url: "/Profiles/Filtering",
dataType: "json"
}
},
},
change: function() {
var value = this.value();
if (value) {
grid.data("kendoGrid").dataSource.filter({ field: "Id", operator: "eq", value: parseInt(value) });
} else {
grid.data("kendoGrid").dataSource.filter({});
}
}
});
});
</script>
所以问题是下拉列表没有显示以及值/数据,有什么想法吗?