This is a migrated thread and some comments may be shown as answers.

Cascading combobox not populated with data

3 Answers 415 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 2
Brett asked on 10 Oct 2012, 09:13 PM
This is odd behavior. I'm not quite sure what it is I'm doing wrong, as I've reproduced the example contained within the Kendo UI MVC distribution package. I have two combo boxes. The second combo box cascades from the first. The controller action that populates the second combo box does fire, the expected query parameter taken from the value of the first combo box is passed to it, and the browser does receive the expected JSON returned from the controller. However, the second combo box remains empty. Here is my code:

Controller:
public JsonResult GetPosts()
{ return Json(_manager.GetPosts().Select(p => new { PostName = p.Name, PostValue = p.Id }), JsonRequestBehavior.AllowGet); }
 
public JsonResult GetUnits(string postId)
{
 Guid id;
 
 if (string.IsNullOrEmpty(postId) || !Guid.TryParse(postId, out id))
 { return null; }
 
 return Json(_manager.GetUnits(id).Select(u => new { UnitName = u.Name, UnitValue = u.Id }), JsonRequestBehavior.AllowGet);
}

View:
@(Html.Kendo().ComboBox()
         .Name("Post")
         .DataTextField("PostName")
         .DataValueField("PostValue")
         .DataSource(ds => ds.Read("GetPosts", "Shared")))
 
@(Html.Kendo().ComboBox()
         .Name("Unit")
         .DataTextField("UnitName")
         .DataValueField("UnitValue")
         .DataSource(ds => ds.Read(read => read.Action("GetUnits", "Shared").Data("filterUnits")).ServerFiltering(false))
         .CascadeFrom("Post"))
 
<script type="text/javascript">
  function filterUnits() {
    return {
      postId: $('#Post').val()
    };
  }
</script>

The JSON returned by the GetUnits(string) controller action to the browser is:
[{"UnitName":"Defense Media Activity","UnitValue":"b39e64f3-60a4-4c48-aa98-201229c88302"},{"UnitName":"Kimbrough","UnitValue":"f4d88089-32d7-4dd4-ab6f-37a3cb4d0142"}]

Thank you for any assistance you can provide.

UPDATE

If I change the second UI control from a ComboBox to a DropDownList, it renders the options as expected. Any reason why the ComboBox does not get populated and render the data it receives?

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 12 Oct 2012, 03:50 PM
Hello Brett,

 
I am not sure what could cause this erroneous behavior. Could you please send us a simple test project, which replicates the issue? Thus I will be able to review it locally and advice you further.

Kind regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brett
Top achievements
Rank 2
answered on 15 Oct 2012, 01:18 PM
Attached are the models, views, and controllers that recreate the behavior I am experiencing. I could not upload a working project as it was larger that the 2 MB limit you place on files in your forums.
0
Accepted
Georgi Krustev
Telerik team
answered on 16 Oct 2012, 01:35 PM
Hello Brett,

 
Thank you for the test project. After further investigation I noticed the ServerFiltering(false) method, which means that the combobox will not make further requests, because it assumes that all required data is get in the first request. Because "Unit" combobox has autoBind set to true, it will make request on page load and will not get any data. Then when parent combobox raises change event the children will not make any additional requests and will stay empty. Set server filtering to true. If you need to find more information about this I will suggest you check this help topic.

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ComboBox
Asked by
Brett
Top achievements
Rank 2
Answers by
Georgi Krustev
Telerik team
Brett
Top achievements
Rank 2
Share this question
or