Kendo多选组件将占位符作为值传递

时间:2017-03-16 21:03:36

标签: kendo-ui kendo-asp.net-mvc multi-select

我有一个带有 Kendo UI MultiSelec t组件的表单,用于 ASP.NET MVC / Razor

@(Html.Kendo().MultiSelectFor(m => m.Ids)
                .Filter(FilterType.Contains)
                .AutoBind(true)
                .MinLength(3)
                .Delay(500)
                .DataTextField("Value")
                .DataValueField("Key")
                .Placeholder("Please fill")
                .DataSource(
                    ds => ds.Read(
                        r => r.Action("FillMultiSelect", "ReportsController", new { companyId = IdentityManager.CompanyID, search = string.Empty })
                        ).ServerFiltering(true)
                )
            )

用于过滤的JavaScript:

var $ids = $("#Ids").data("kendoMultiSelect");

$ids.dataSource.transport.options.read.data = basicFilter($ids);

var basicFilter = function ($element) {
   return {
       companyId: self.form.getModel().CompanyId,
       search: $element.input.val()
   }
}

当我在“Ids”MultiSelect中键入搜索文本时,传递给ASP.NET MVC 操作的参数是元素的占位符的值:

enter image description here

enter image description here

enter image description here

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:0)

错误在于从MultiSelect组件中检索值。我应该使用来自filters对象的filter数组,由data事件传递。正确的JavaScript:

window.global.setDatasourceTransportFilter($(“#Ids”),“kendoMultiSelect”,basicFilter);

var basicFilter = function (e) {
   return {
       companyId: self.form.getModel().CompanyId,
       search: e.filter && e.filter.filters[0] ? e.filter.filters[0].value : ""
   }
}