我正在尝试在服务器端处理 Kendo UI ComboBox 的过滤。我在视图中有以下代码
$('#Solicitor').kendoComboBox({
placeholder: "@T("Enter the partial Name or Primary ID of the Entity.").Text",
dataTextField: "text",
dataValueField: "id",
autoBind: false,
minLength: 3,
filter: "startswith",
dataSource: {
serverFiltering: true,
transport: {
read: {
url: "@Url.Action("Index", "EntitiesAdmin", new { area = "BizNet.Entity"})",
dataType: "json"
}
}
}
});
当我在 ComboBox 中输入一些内容时,例如。CAR,使用 Fiddler2,我可以看到以下查询字符串正在发送到服务器
filter%5Blogic%5D=and&filter%5Bfilters%5D%5B0%5D%5Bvalue%5D=CAR&filter%5Bfilters%5D%5B0%5D%5Bfield%5D=text&filter%5Bfilters%5D%5B0%5D%5Boperator%5D=startswith&filter%5Bfilters%5D%5B0%5D%5BignoreCase%5D=true
解析后,它看起来像这样
filter[logic]:and
filter[filters][0][value]:CAR
filter[filters][0][field]:text
filter[filters][0][operator]:startswith
filter[filters][0][ignoreCase]:true
从外观上看,ComboBox 正在通过 ajax 向服务器发送一个名为filter的 javascript 数组。如何在我的控制器中处理这样的数组?
public ActionResult Index(THE_TYPE_TO_USE filter) {
}
我应该放THE_TYPE_TO_USE
什么?我试过了object
,dynamic
但他们都产生了一个空过滤器。请注意,从客户端发送的过滤器也可能很复杂,如下所示:
$('#Solicitor').kendoComboBox({
placeholder: "@T("Enter the partial Name or Primary ID of the Entity.").Text",
dataTextField: "text",
dataValueField: "id",
autoBind: false,
minLength: 3,
filter: "startswith",
dataSource: {
serverFiltering: true,
// Additional filters which span several levels deep
filter: {
filters: [
{
filter: {
logic: "or",
filters: [
{ field: "content-type", operator: "eq", value: "Company" },
{ field: "content-type", operator: "eq", value: "Firm" }
]
}
}
]
},
transport: {
read: {
url: "@Url.Action("Index", "EntitiesAdmin", new { area = "BizNet.Entity"})",
dataType: "json"
}
}
}
});
这将产生以下解析的查询字符串
filter[filters][0][filter][logic]:or
filter[filters][0][filter][filters][0][field]:content-type
filter[filters][0][filter][filters][0][operator]:eq
filter[filters][0][filter][filters][0][value]:Company
filter[filters][0][filter][filters][1][field]:content-type
filter[filters][0][filter][filters][1][operator]:eq
filter[filters][0][filter][filters][1][value]:Firm
filter[logic]:and
filter[filters][1][value]:CAR
filter[filters][1][field]:text
filter[filters][1][operator]:startswith
filter[filters][1][ignoreCase]:true
如您所见,数组可以有好几级深。所以我的问题是,我应该在THE_TYPE_TO_USE
上面放什么可以处理任意深度的复杂过滤器?这只能通过 ASP.NET MVC Wrappers 来完成吗?如果是这样,怎么做?