Looking into the Telerik MVC Demos, I tried out the codes for Ajax ComboBox. What I want to achieve is for the items in the ComboBox to perform lazy loading as demonstrated in the ComboBox - Load on Demand section. The demo worked perfectly wherein at initial load the ComboBox does not get populated until you select the combo box.
My problem is that once I implemented the codes in the demo in my project, the ComboBox behaves differently. The ActionResult that is selected in my DataBinding gets called at initial load which should not be the case. It should only get called once I select the ComboBox as demonstrated in the site.
Please help, I tried to compare but I could not find what is causing the difference in behavior.
Below is my code:
View:
<%= Html.Telerik().ComboBox()
.Name("AjaxComboBox")
.AutoFill(true)
.DataBinding(binding => binding.Ajax().Select("_AjaxLoading", "Default1"))
.Filterable(filtering =>
{
filtering.FilterMode(AutoCompleteFilterMode.StartsWith);
})
.HighlightFirstMatch(true)
%>
Controller:
[HttpPost]
public ActionResult _AjaxLoading(string text)
{
Thread.Sleep(1000);
int maxResults = Convert.ToInt32(ConfigurationManager.AppSettings["MaxResults"]);
SelectList list;
IList<LookupEntity> lookupEntity = _service.GetStationNoLookup();
lookupEntity = lookupEntity.Where(o => o.No.StartsWith(text)).Take(maxResults).ToList();
list = new SelectList(lookupEntity, "No", "No");
// return Json(list);
return new JsonResult { Data = list };
}
To further clarify, what is currently happening is that the _AjaxLoading gets triggered upon page load, but based from the demos, it should only trigger once I have selected the combobox.
Please advice. Telerik Version used is 2010.3.1318.235