I got a problem with the Kendo UI MVC DropDownList. I want to do server side filtering. When I click on the control, the list gets populated. This works fine if the current selected item is in the populated list.
But what if I have an address book and the current selected name is "Zorro". I have thousands of names before and when I click on the list, only the first 10 names starting with "A" are shown.
How do I include the currently selected item in the DataSource, so it remains selected if I click on the dropdownlist?
Here is my code:
Razor:
@(Html.Kendo().DropDownListFor(m => m.Id)
.DataValueField(
"Id"
)
.DataTextField(
"DisplayName"
)
.Filter(
"contains"
)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(
"PopulateNames"
,
"PhoneBook"
);
read.Type(HttpVerbs.Post);
})
.ServerFiltering(
true
);
})
)
Controller:
[HttpPost]
public
ActionResult PopulateNames(
string
text)
{
var q = TblName.Query(n => n.ClientId.IsEqualTo(Manager.One.ClientId), n => n.DisplayName.Asc());
if
(text !=
null
&& text.Length > 2) q.Filter(n => n.c.DisplayName.IsLike(text));
q.Top(10);
var rows = q.FetchList<NameLookupViewModel>();
rows.Insert(0, NameLookupViewModel.Default);
return
Json(rows);
}