【问题标题】:KendoUpload FileUpload httppostedfile not working on submit剑道上传文件上传httppostedfile无法提交
【发布时间】:2017-01-09 23:13:42
【问题描述】:

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

现在提交时,我必须再次阅读文件。我正在尝试从 httppostedfilebase 读取文件信息,但它为空,因为保存操作方法返回 JSON。如果我将保存操作方法更改为查看,我将无法在提交时读取 httpostedfilebase。

有解决办法吗?

谢谢!

【问题讨论】:

  • 提供一些代码示例

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


【解决方案1】:
 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.)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-20
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    相关资源
    最近更新 更多