I am using kendo multiselect control for my MVC application where i am trying to bind multiselect but it's not working. Below is my html code:
@(Html.Kendo().MultiSelect()
.Name("ajaxTags")
.Placeholder("Select cities...")
.AutoBind(false)
.DataTextField("CityName")
.DataValueField("CityCode")
.Filter(FilterType.StartsWith)
.BindTo(new SelectList("CityCode","CityName"))
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCities", "DutyTravel");
});
source.ServerFiltering(true);
})
.HtmlAttributes(new { style = "width: 60%;" })
)
So, here I am using AutoBind(false)
so only when the user expands the, then it makes a server call and gets the data.
And, below is my controller code:
public JsonResult GetCities([DataSourceRequest] DataSourceRequest request)
{
List<DutyTravelPerDiemMaster> lstCities = null;
lstCities = (List<DutyTravelPerDiemMaster>)HttpContext.Session["GetPerdiemList"];
var lstFilteredCity = from d in lstCities
select new
{
CityCode = d.CityCode,
CityName = d.CityName
};
return Json(lstFilteredCity.ToList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
In this method, I see that all the city codes and city names are populating, but not showing in the multi-select.