KendoUpload FileUpload httppostedfile无法提交

时间:2017-01-09 23:13:43

标签: asp.net-mvc kendo-ui kendo-asp.net-mvc asyncfileupload

我在我的应用程序中使用@(Html.Kendo()。Upload()。我必须从csv获取前5条记录并将其绑定到javascript中的kendo网格。我正在阅读来自的文件信息httpsosfilebase并将前5条记录作为JSON结果返回保存操作方法。在javascript中上传成功我绑定了网格。

现在提交,我必须再次阅读该文件。我试图从httppostedfilebase读取文件信息,但它是null,因为save action方法返回JSON。如果我将保存操作方法更改为查看,则我可以在提交时读取httpostedfilebase。

有解决方法吗?

谢谢!

1 个答案:

答案 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.)
}