0

ボタンをクリックすると剣道グリッドデータを投稿しようとしています。データをExcelファイルに保存したいのですが、データセットが大きいときにkendoがグリッドデータを保存するために提供するデフォルトオプションが失敗します。だから、私はサーバー側でExcelの操作をしようとしています。私の問題は、コントローラにデータを渡すことができないことです。カスタムコマンドをクリックして剣道グリッドデータをMVCコントローラにポスト

コード: ビュー

@(Html.Kendo().Grid(Model) 
.Name("OutputCashGrid") 
.Events(ev => ev.Edit("onEdit")) 
.Columns(columns => 
{ 


    columns.Bound(p => p.ClientID).Hidden(); 

    columns.Bound(p => p.LoadID).Title("Loadid").Hidden(); 
    columns.Bound(p => p.Level1).Title("Level1").Width(130); 
    columns.Bound(p => p.Level2).Title("Level2").Width(130); 
    columns.Bound(p => p.AsOfDate).Title("AsOfDate").Width(150).Format("{0:d}").Width(130); 

}) 

    .ToolBar(toolbar => 
       {     
        toolbar.Save().HtmlAttributes(new { id = "Save" }).SaveText("Save External Balances and Comments"); 
        toolbar.Custom() 
        .Text("Export To Excel") 
        .HtmlAttributes(new { @class = "export" }) 
        .Url("javascript:myFunction()"); 
       }) 
       .Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode. 
.HtmlAttributes(new { style = "height: 550px;" }) 

.Groupable() 
      //.Excel(excel => excel 
      // .AllPages(true) 

      //       .FileName("CashSummary_" + @ViewBag.goClientName + "_" + @ViewBag.Asofdate.ToString("MM/dd/yyyy") + ".xlsx") 
      // .Filterable(true) 
      //   .ProxyURL(Url.Action("Excel_Export_Save", "SaveRec")) 
      //  ) //this fails for large datasets 
.Reorderable(r => r.Columns(true)) 
.Sortable() 
.ColumnMenu() 
.DataSource(dataSource => dataSource 
    .Ajax() 
    .Events(e2 => e2.Change("vChange")) 
    .PageSize(50) 
    .ServerOperation(false) 
     .Batch(true) // Enable batch updates. 
        .Model(model => 
         { 
          model.Id(p => p.OutputcashID); // Specify the property which is the unique identifier of the model. 
          //model.Field(p => p.OutputcashID).Editable(false); // Make the ProductID property not editable. 

    .Update("Editing_Update", "SaveRec",new { loadid = @loadid,[email protected] }) 
     ) 


     .Pageable(pageable => pageable 
      .Refresh(true) 
      .Input(true) 
      .Numeric(false) 
     ) 
        .Resizable(resize => resize.Columns(true)) 
        .Selectable() 




       ) 

私はそれが行動に当たるが、データを渡していないカスタムツールバー内のURL(「アクション」、「コントローラ」)を使用してみました。 HttpPostでアクションを飾ると、404エラーが出ます。

JS機能を呼び出す

function myFunction() { 
     var grid = $("#OutputCashGrid").getKendoGrid(); 
     var data = JSON.stringify(grid.dataSource.view()); 
     $.ajax({ 
      url: '/SaveRec/Excel_save', 
      type: 'POST', 
      data: data, 
      async: true, 
      processData: false 
     }); 
    } 

コントローラー:

// [AcceptVerbs(HttpVerbs.Post)] get 404 error when using http.post, without this it hits the action but doesn't pass data. 
     public ActionResult Excel_save([DataSourceRequest]DataSourceRequest request,[Bind(Prefix = "models")]IEnumerable<OutputCash> results) 
     { 
//gives me null for results 
      var WFSEntities=new WFSEntities(); 

      var grid = WFSEntities.OutputCashes; 

      var gridresults = grid.ToDataSourceResult(request).Data; //returns all the data from the table. 

      //Create new Excel workbook 
      var workbook = new HSSFWorkbook(); 

      //Create new Excel sheet 
      var sheet = workbook.CreateSheet();  

     //create excel sheet, removed code for brevity 


      return File(output.ToArray(), //The binary data of the XLS file 
       "application/vnd.ms-excel", //MIME type of Excel files 
       "Output.xls");  //Suggested file name in the "Save as" dialog which will be displayed to the end user 




     } 
+0

投稿された行データの形式をブラウザのdevツールで見て、組み込みの剣道の保存形式と比較してください。 MVCモデルバインダーが[Bind(Prefix = "models")] IEnumerable 結果にバインドできるように、投稿された行データを同じ方法でフォーマットする必要があります。JSON.stringify()は同じ/正しいものを生成しませんデータ形式。 –

答えて

0

は全体の運用サーバー側を行うには、あなたはAJAX呼び出しからコントローラにデータを渡しません。コントローラーは、渡したURLを取り込み、コントローラー内のエクスポート用のデータを取得します。それが新鮮なサーバー側に引っ張られた後、ワークシートジェネレータに渡します。もっとも難しいのは、コントローラーのアクションがデータを取り込む前に、データに適用したいフィルター/ページを渡すことです。また、サーバー側の処理が行われている間にローディングイメージを表示することも有益です。

関連する問題