KendoUpload FileUpload httppostedfile not working on submit

821 views Asked by At

I am using @(Html.Kendo().Upload() in my app. I have to take the top 5 records from csv and bind it to kendo grid in javascript. I'm reading the file info from httppostedfilebase and returning the top 5 records as JSON result in save action method. On Upload success in javascript i'm binding the grid.

Now on submit, i have to read the file again. i'm trying to read the file information from httppostedfilebase but it is null because the save action method returns JSON. If i change the save action method to view, i'm ablet o read the httpostedfilebase on submit.

Is there a workaround?

Thanks!

1

There are 1 answers

0
user3123734 On
 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.)
}