I have a Kendo DropdownList that I can't get to filter - on looking at the data received in the controller to the following function I notice that the "string text" is always null:
[OutputCache(NoStore = true, Duration = 0)]
public JsonResult GetAssemblys(string text, long site)
{
return Json(CreateFilteredList(text, site, (long)AssetTypeEnum.Assembly), JsonRequestBehavior.AllowGet);
}
This is the code for the DropDownList:
<div>@(Html.Kendo().DropDownList()
.Name("AssemblySelector")
.DataTextField("AssetName")
.DataValueField("AssetId")
.HtmlAttributes(new { style = "width: 570px;" })
.OptionLabel("Select assembly...")
.DataSource(s =>
{
s.Read(r => r.Action("GetAssemblys", "Form707B").Data("getsite"));
s.ServerFiltering(true);
})
.Filter(FilterType.Contains)
.Height(300)
.SelectedIndex(0))
This worked before I added the .Data("getsite")) part to to the read method. getsite() returns a long called site (this is successfully received in the controller).
What is often not known by people using the MVC Builder is that fluent builder puts a default read data handler to send the filter text to their controller.
if you override the data handler you need to send the text filter yourself or call the method it usually calls which is the following
if (DataSource.ServerFiltering && !DataSource.Transport.Read.Data.HasValue() && DataSource.Type != DataSourceType.Custom) {
DataSource.Transport.Read.Data = new ClientHandlerDescriptor {
HandlerName = "function() { return kendo.ui.DropDownList.requestData(jQuery(\"" + EscapeRegex.Replace(Selector, @"\\$1") + "\")); }"
};
}
to do so your getsite function should look like this.
function getsite() {
// drop down element
var $dd = $('#AssemblySelector');
// widget
var dd = dd.data('kendoDropDownList');
var filterText = dd.input.text();
var site = null; // do your logic for this.
return {
site: site,
text: filterText
};
}
or
function getsite() {
// drop down element
var $dd = $('#AssemblySelector');
// widget
var dd = dd.data('kendoDropDownList');
var ret = kendo.ui.DropDownList.requestData($dd);
ret['site'] = site;
return ret;
}