2017-01-09 2 views
0

내 앱에서 @ (Html.Kendo()를 사용하고 있습니다.) 앱에서 상위 5 개 레코드를 가져 와서 자바 스크립트의 검도 그리드에 바인딩해야합니다. httppostedfilebase에서 파일 정보를 읽고 상위 5 개 레코드를 JSON 결과로 저장 액션에 저장합니다. 자바 스크립트에서 성공 업로드하기 저는 바운딩을 바인딩하고 있습니다.KendoUpload FileUpload httppostedfile이 작동하지 않습니다.

제출할 때 파일을 다시 읽어야합니다. m httppostedfilebase에서 파일 정보를 읽으려고하지만 저장 액션 메서드가 JSON을 반환하기 때문에 null입니다. 저장 작업 메서드를 변경하면 게시 할 때 httpostedfilebase를 읽습니다.

해결 방법이 있습니까? ?

감사!

+0

일부 코드 샘플을 제공하십시오. –

답변

0
Code Sample: 

view 
---- 

@(Html.Kendo().Upload()    
          .Name("uploadTemplate") 
          .Messages(m => m.Select("")) 
          .ShowFileList(true) 
          .Async(a => a 
           .Save("UploadData", "Lead") 
           .AutoUpload(true) 
          ) 
          .Multiple(false) 
          .Events(events => events 
          .Select(UploadFileControl.onSelect") 
          .Success("UploadFileControl.onSuccess") 
          .Upload("UploadFileControl.onUpload") 
          ) 
         ) 


form 
---- 
    @using (Html.BeginForm("", "", FormMethod.Post, new { id = "LoadForm", enctype = "multipart/form-data" })) 

js 
-- 

function SubmitForm(val) { 


       var url = '@Url.Action("fileSubmit", Test")'; 
        console.log(url); 
        $.ajax({ 
         url: url, 
         type: 'POST', 
         data: $('form#LoadForm').serialize(), 
         async: false, 
         success: function (data) { 
          alert("success"); 
         }, 

         error: function (data, xhr, error) { 
          alert("error"); 
         } 
        }); 
       } 


onSuccess(e) 

{ var grid = $("#grid").data("kendoGrid"); 
     var origData = e.response; 
     grid.dataSource.data(origData); 
} 

document ready 
-------------- 

var grid = $("#grid").kendoGrid({ 
         groupable: false, 
         scrollable: true, 
         columnMenu: true 
        }).data("kendoGrid"); 


code behind 
----------- 

public JsonResult UploadData(IEnumerable<HttpPostedFileBase> uploadTemplate, FileModel fileModel) 
     { 

      Stream inputFileStream = new MemoryStream(); 
      string[] result = new string[] { }; 

      if (uploadOnly) 
      { 
       if (uploadTemplate != null) 
       { 
        try 
        { 
         foreach (var file in uploadTemplate) 
         { 
          inputFileStream = file.InputStream; 
      } 

//       GET TOP N ROWS AND ASSIGN TO parentRow 

       return Json(parentRow, JsonRequestBehavior.AllowGet);    
      }    
      return null; 
     } 

public ActionResult fileSubmit(IEnumerable<HttpPostedFileBase> uploadTemplate, FileModel fileModel) 
     { 
//retrieve uploadTemplate here (no values in uploadTemplate.) 
} 
관련 문제