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:
View:
The JSON returned by the GetUnits(string) controller action to the browser is:
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?
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?