I have some odd behavior happening in a combo box.
I have a simple combo box setup.
I have a link button that calls this javascript code.
This is the code in the controller that is creating the json object.
Everything works perfectly on the first time I click on the link to populate the combo box. If I select a value in the combo box, say for example it's Id happens to be 1234, when I click on the link again (with the intention of repopulating the combo box with different set of values) with a different value that returns back an empty object (no results in the list), the combo box is left with no values in the drop down (which would be correct), but the text in the combo box say 1234.
The box is left with the Id on the previous value I selected. I thought when I call setDataSource it rebinds the combo box, meaning it removes previously selected values. Why is the combo box setting it's text as the previous value (Id) that I had selected when the second datasource happens to be an empty list?
Thanks,
Tad
I have a simple combo box setup.
@(Html.Kendo().ComboBox() .Name("vendorsforClass") .AutoBind(false) .HtmlAttributes(new { style = "width: 300px;" }) .DataTextField("Name") .DataValueField("Id") )function getVendorsForClass() { var txtValue = $("#txtSearchClassVendor").val(); $.getJSON('@Url.Action("GetVendorListByClass","RCS", new {classes = "class"}, "http")/' + txtValue, function (data) { var combo = $("#vendorsforClass").data("kendoComboBox"); combo.setDataSource(data); combo.refresh(); });}public JsonResult GetVendorListByClass(string classes) { var vendors = new List<VendorList>(); var classId = classes.Split('/')[1]; int outId; if (int.TryParse(classId, out outId)) { vendors = new VendorListFactory().GetVendors(outId); } return this.Json(vendors.Select(v => new { v.Name, v.Id }), JsonRequestBehavior.AllowGet); }The box is left with the Id on the previous value I selected. I thought when I call setDataSource it rebinds the combo box, meaning it removes previously selected values. Why is the combo box setting it's text as the previous value (Id) that I had selected when the second datasource happens to be an empty list?
Thanks,
Tad