2017-11-22 11 views
0

버튼을 클릭하면 검도 그리드 데이터를 게시하려고합니다. 데이터를 엑셀 파일에 저장하려고합니다. 데이터 세트가 클 때 검도 데이터를 저장하기 위해 검도에서 제공하는 기본 옵션이 실패합니다. 그래서 서버 측에서 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

가 전체 작업의 서버 측을 수행하려면, 당신은 아약스 호출에서 컨트롤러로 데이터를 전달하지 않습니다. 컨트롤러는 전달한 URL을 받아 들여 컨트롤러에서 내보내기를 위해 데이터를 가져옵니다. 그것이 신선한 서버 쪽을 당긴 후, 당신은 워크 시트 생성기로 전달합니다. 가장 까다로운 부분은 컨트롤러 액션이 데이터를 얻기 전에 데이터에 적용 할 필터/페이지를 전달하는 것입니다. 또한 서버 측 처리가 진행되는 동안로드 이미지를 제공하는 것이 좋습니다.