2017-01-09 165 views
0

我正在使用@(Html.Kendo()。Upload()在我的應用程序中,我必須從csv中取出前5條記錄並將其綁定到JavaScript中的kendo網格。讀取來自httppostedfilebase的文件信息,並返回前5條記錄作爲JSON結果保存操作方法在上傳成功在javascript我綁定網格KendoUpload FileUpload httppostedfile無法提交

現在提交,我必須再次閱讀文件。 m試圖從httppostedfilebase讀取文件信息,但它是空的,因爲save操作方法返回JSON。如果我更改save action方法來查看,我不能讀取提交後的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.) 
}