I need to change the available options in a dropdownlist based on what i user has entered into a textbox on the same page. My thought was to attache to the change event on that textbox and rebind/read the kendo dropdown list.
When the page first loads everything works as expected.
When the user changes the MaxSize textbox the rebindRooms function get called and processed completely, but the GetSize function never gets called and the no ajax requests get fired.
How to I force the dropdown to rebind from the server?
.cshtml
textbox
dropdownlist
.js
.cs
Thanks!
-Logan
When the page first loads everything works as expected.
When the user changes the MaxSize textbox the rebindRooms function get called and processed completely, but the GetSize function never gets called and the no ajax requests get fired.
How to I force the dropdown to rebind from the server?
.cshtml
textbox
@Html.DisplayFor(m => m.MaxSize)
dropdownlist
@(Html.Kendo().DropDownListFor(m => m.SchedulePreference.DesiredRoomId) .DataTextField("Value").DataValueField("Key") .DataSource(ds => ds.Read(read => read.Action("RoomDropDown_Read", "Scheduling") .Data("GetSize")) .ServerFiltering(true) ) ).js
<script type="text/javascript"> $(document).ready(function () { $('#MaxSize').change(rebindRooms); });</script>function rebindRooms(e) { var el = e.currentTarget.value; var ddl = $("#SchedulePreference_DesiredRoomId").data("kendoComboBox"); if (ddl && ddl.dataSource) { ddl.dataSource.read(); }}function GetSize() { var el = $('#MaxSize'); var s = el ? el.val() : 0; return { size: s }}.cs
[NoCache]public ActionResult RoomDropDown_Read(int size=0){ var list = _uow.RoomRepository.GetAll().OrderBy(o => o.DropDownText).Where(w => w.MaxSize >= size).Select(s=>new KeyValuePair<int,string>(s.Id,s.DropDownText)).ToList(); return Json(list, JsonRequestBehavior.AllowGet);}Thanks!
-Logan