I'm trying to handle filtering of Kendo UI ComboBox on server side. I have the following codes in the view
$('#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"
}
}
}
});
When I typed something into the ComboBox, eg. CAR, using Fiddler2, i can see the following query string is being sent to the server
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
when parsed, it'll look something like this
filter[logic]:and
filter[filters][0][value]:CAR
filter[filters][0][field]:text
filter[filters][0][operator]:startswith
filter[filters][0][ignoreCase]:true
From the looks of it, the ComboBox is sending a javascript array named filter through ajax to the server. How do I handle such array in my controller?
public ActionResult Index(THE_TYPE_TO_USE filter) {
}
What should I put in THE_TYPE_TO_USE
? I've tried object
and dynamic
but they both produced a null filter. Please note that the filter sent from the client can be complex too like the following:
$('#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"
}
}
}
});
which will produce the following parsed query string
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
As you can see, the array can be several levels deep. So my question is, What should I put in THE_TYPE_TO_USE
above which can handle complex filter of arbitrary depth? Can this only be done with the ASP.NET MVC Wrappers? If so, how?