2016-10-16 9 views
0

こんにちは私は剣道MVCグリッドin cellモードを使用しています。カスケードドロップダウンリストを作成しようとしています。SubCategoryドロップダウンリストに基づいてドロップダウンリストを入力しています。私は私ではなく、実際の値のundefinedとしてJSONによって返される結果を得ることを除いて正常に動作し、すべてを持っている、 はここajax一部のコードここ
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"); 

されている: -

<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> 
ADVで

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); 
     } 

感謝 - :

そして、ここでは簡単なコントローラ(SubSubCategories)でありますANCE :)

答えて

0

問題は、コントローラからデータを取得JQueryコードでは、私はArrayの内部のデータを入れているし、私は、ここに解決策があるArrayこと からDropDownListを結合していた: -

<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> 
関連する問題