I just worked through adding a MultiSelect fillter on a page with a grid, and didn't see anything in the forums that addressed this issue, so I thought I would post the result that I came up with.
Above is what I came up with.
Telerik came up with the following:
Hopefully, this will be helpful to somebody.
<%= Html.Kendo().MultiSelectFor(m => m.FilterRoleIds)
.Placeholder("Select Roles")
.DataTextField("RoleName")
.DataValueField("ApRoleId")
.BindTo(ViewBag.ApRolesList)
%>
<%= Html.Kendo().MultiSelectFor(m => m.FilterCompanyIds)
.Placeholder("Select Companies")
.DataTextField("CompanyName")
.DataValueField("CompanyId")
.BindTo(ViewBag.CompanyList)
%>
<
script
language
=
"javascript"
type
=
"text/javascript"
>
function additionalData() {
return {
roleIds: "<%= ApRoleController.ReturnListValues(Model.FilterRoleIds) %>",
companyIds: "<%= ApRoleController.ReturnListValues(Model.FilterCompanyIds) %>"
};
}
</
script
>
public static string ReturnListValues(List<
string
> list)
{
if (list == null || list.Count == 0) return "";
string s = string.Empty;
foreach (var item in list)
{
if (s != string.Empty)
s += ",";
s += item;
}
return s;
}
Telerik came up with the following:
<
script
language
=
"javascript"
type
=
"text/javascript"
>
function additionalData() {
var roleIds = <%= Html.Raw(Json.Encode(Model.FilterRoleIds)) %>;
var data = {};
for(var i=0; i<
roleIds.length
;i++){
data["FilterRoleIds[" + i + "]"] = roleIds[i];
}
return data;
}
</script>