Json Returns "Undefined" 到 Kendo 下拉列表?

Json Returns "Undefined" to Kendo Dropdownlist?

您好,我正在使用 Kendo MVC Grid in cell 模式,我正在尝试构建级联下拉列表,我正在尝试根据 [ 填充 SubCategory 下拉列表=19=] 下拉列表。除了我得到 JSON 作为 undefined 而不是实际值返回的结果外,我一切正常, 这是代码

@(Html.Kendo().Grid<WebApplication6.Models.SubSubCategory>()
      .Name("grid")
      .Events(events => events.Change("Grid_OnRowSelect"))
      .Columns(columns =>
      {
          columns.ForeignKey(c => c.CategoryID, (System.Collections.IEnumerable)ViewData["Category"],"CategoryID","CategoryName").Title("Category");
columns.ForeignKey(c => c.SubCategoryID (System.Collections.IEnumerable)ViewData["SubCategory"], "SubCategoryID", "SubCategoryName").Title("Sub-Category");

这是ajax部分:-

<script>
    Grid_OnRowSelect = function (e) {
        var CatID = (this.dataItem(this.select()).CategoryID);
         $.ajax({
                //url: "SubSubCategories/SearchSubCategory",
                url:'@Url.Action("SearchSubCategory", "SubSubCategories")',
                type: "GET",
                data: { CategoryID: CatID },
                dataType: "json",
                success: function (retData) {
                    if (JSON.stringify(retData) != "[]") {
                        var ddl = $('#SubCategoryID').data("kendoDropDownList");
                        ddl.setDataSource(retData);
                        ddl.refresh();



                    }else {
                             alert("No");
                   }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }

            });
<script>

这里是简单的控制器(SubSubCategories):-

 public JsonResult SearchSubCategory(int CategoryID)
        {

          var x = ((db.SubCategories.Select(p => 
          new { CategoryID = p.CategoryID, SubCategoryID = p.SubCatgeoryID, SubCategoryName = p.SubCategoryName }))
          .Where(p => p.CategoryID == CategoryID));
            return Json(x, JsonRequestBehavior.AllowGet);
        }

提前致谢:)

问题出在从控制器检索数据的 JQuery 代码中,我已将数据放在 Array 中,然后我从 DropDownList 绑定了 DropDownList Array,这里是解决方案:-

    <script>
    Grid_OnRowSelect = function (e) {
        var CatID = (this.dataItem(this.select()).CategoryID);
        //alert(CatID);
        document.getElementById("cat_id").innerHTML = CatID;
            $.ajax({
                url:'@Url.Action("SearchSubCategory", "SubSubCategories")',
                type: "GET",
                data: { CategoryID: CatID },
                success: function (retData) {
                    if (JSON.stringify(retData) != "[]") {
                        //var ddl = $('#SubCategoryID').data("kendoDropDownList");
                        var x = []
                        for (i = 0; i < retData.length; i++) {
                            x.push(retData[i]);
                        }
                        $("#SubCategoryID").kendoDropDownList({
                            dataTextField: "SubCategoryName",
                            dataValueField: "SubCategoryID",
                            dataSource: x
                        });
                    }
                    else {
                        alert("No sub-categories were found for this category");
                    }
                },
                    error: function (jqXHR, textStatus, errorThrown) {
                    //alert(jqXHR.responseText);
                }

            });
    }
</script>