2016-12-20 7 views
1

他にも同様の問題があり、同様の問題を抱えていると同時に重複してマークしないでください。剣道UIがボタンクリックでデータを読み込まない

私はボタンクリックで剣道グリッドを読み込もうとしていますが、私にとっては効果がないようです。私は下の私のファイルを添付しています:

KendoData.cshtml

<div id="grid"> 
     @(Html.Kendo().Grid(<MvcApplication1.Models.Customer) 
       .Name("AjaxGrid") 
       .AutoBind(false) 
      .DataSource(dataSource => dataSource 
      .Ajax() 
      .PageSize(20) 
        .Read(read => read.Action("KendoDataAjaxHandle", "Default1Controller")) 
     )   
       .Columns(columns => 
       { 
        //Create a column bound to the ProductID property. 
        columns.Bound(customer => customer.CustomerAltID); 
        //Create a column bound to the ProductName property. 
        columns.Bound(customer => customer.CustomerName); 
        //Create a column bound to the UnitsInStock property. 
        columns.Bound(customer => customer.Gender); 
       }) 
       .Pageable() //Enable the paging. 
       .Sortable() //Enable the sorting. 
       .Groupable() 
     ) 

    </div> 

    <style> 
     #AjaxGrid { 
      display: none; 
     } 
    </style> 

    <button class="btn btn-warning grid" type="button">Load Ajax KendoData</button> 

jQueryの

$('button.grid').click(function() { 
     $("#AjaxGrid").data("kendoGrid").dataSource.read(); 
     $("#AjaxGrid").css("display", "block"); 
    }); 

コントローラ

public class Default1Controller : Controller 
    { 
     // 
     // GET: /Default1/ 

     private Sales_DW db= new Sales_DW(); 

     public ActionResult KendoData() 
     { 
      return View(); 
     } 

public ActionResult KendoDataAjaxHandle([DataSourceRequest]DataSourceRequest request) 
     { 
      IQueryable<Customer> products = db.Customers; 
      DataSourceResult result = products.ToDataSourceResult(request); 
      return Json(result, JsonRequestBehavior.AllowGet); 
     } 
} 

ボタンをクリックすると、コンソールにCannot read property dataSource of undefinedエラーが表示されます。 誰かが私がここで間違ったことを教えてもらえますか?前もって感謝します。

答えて

1

現在、グリッド構築中にBinding to local dataアプローチを実行しています。

Bind with Remote Dataにする場合は、グリッドのDataSourceを設定する必要があります。

@(Html.Kendo().Grid<MvcApplication1.Models.Customer>() 
    //other details 
    .DataSource(dataSource => dataSource 
     .Ajax() 
     .PageSize(20) 
     .Read(read => read.Action("ActionName", "ControllerName")) 
    ) 
) 
+0

ありがとうRajshekhar。これを試してみましたが、それでも同じエラーです。 –

+0

@AakashThakur私はここで小さな更新をしました.Grid () 'この構文でチェックしてください。 –

+0

まだ同じエラーが発生しています。 –

0

this

の表情がvisibility:hidden;私は、コードをテストしhave't

、そのわずか推測を設定していてください。

関連する問題