Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to move attachments through kendo upload from one view to another view

We are working on Kendo MVC UI, where we are sending the data from one view to another view, all the data(testbox, dropdown) are getting passed to the next view except the attachments(pdf,xlsx).

Below is the code which in the controller which we have written to capture from view and save the data and pass the same data to the another view and bind the data to the kendo controls(upload control also)

 public ActionResult SaveData(System.Web.Mvc.FormCollection form, IEnumerable<HttpPostedFileBase> files) // insert operation
    {
        //*************************//
        if (form != null)
        {
            string ddluserexceptioncategory = Convert.ToString(form["txtexceptioncategory"], CultureInfo.InvariantCulture);

            if (!string.IsNullOrEmpty(ddluserexceptioncategory))
            {
                ddluserexceptioncategory = ddluserexceptioncategory.Trim();
            }
            if (ddluserexceptioncategory == "User Management")
            {
                //Bind the data to the class object(_clsObj)


                if (files != null)
                {
                    TempData["FileName"] = files;
                    _clsObj.Files = files;
                }
                TempData["SecondViewData"] = _clsObj;


                return RedirectToAction("ExceptionType", "Home", new { id = 0, regionId = _clsObj.RegionId, status1 = "New,In Progress", keyword1 = string.Empty });
            }
        }

        string regions = "", statusValue = "";
        if (form != null)
        {
            regions = form["hiddenregionselected"] + "";
            statusValue = form["hiddenstatusselected"] + "";
        }

        return RedirectToAction("homepage", "Home", new { region = regions, status = statusValue });
    }

Below is the code which we bind the request to the second

  @if (TempData["FileName"] != null)
 {
IEnumerable<HttpPostedFileBase> firstFile = (IEnumerable<HttpPostedFileBase>)TempData["FileName"];

<div class="k-dropzone">
    <div class="k-button k-upload-button">
        <input name="files" type="file" data-role="upload" multiple="multiple" autocomplete="off" tabindex="-1" class="valid" style="display: none;">
        <input id="files" name="files" type="file" data-role="upload" multiple="multiple" autocomplete="off">
        <ul id="files1" class="k-upload-files k-reset">

            @foreach (var file in firstFile)
            {
                string filename= Path.GetFileName(file.FileName);
                <li class="k-file" data-uid="7aa03676-4dac-468e-b34a-99ac44d23040">
                    <span class="k-icon k-success">uploaded</span>
                    <span class="k-filename" title="@filename">@filename</span>
                    <strong class="k-upload-status">
                        <span class="k-icon k-delete"></span>
                    </strong>
                </li>
            }
        </ul>

    </div>
</div>
<script>
    jQuery(function()
    {jQuery("#files").kendoUpload(
    {"select":uploadselect,
        "localization":{"select":"Browse file",
            "headerStatusUploading":"uploading..",
            "headerStatusUploaded":"uploded.."},
        "async":{"saveUrl":"/Home/Save",
            "autoUpload":false,"removeUrl":
                "/Home/Remove"}});});

</script>
}
  else
 {
@(Html.Kendo().Upload().Name("files").Async(a => a.Save("Save", "Home").Remove("Remove", "Home").AutoUpload(false)).Multiple(true).Messages(m =>
{
    m.Select("Browse file");

}).Events(events => events.Select("uploadselect")))

}

Any suggestions or help is much appreciated.

like image 341
Dinesh Haraveer Avatar asked Aug 26 '16 13:08

Dinesh Haraveer


1 Answers

My guess is that the issue is coming from using TempData to get this data from your markup to your controller or vice versa.

As you are likely aware, anything you put into TempData is discarded after the next request completes (Using Tempdata in ASP.NET MVC - Best practice, http://www.codeproject.com/Articles/476967/What-is-ViewData-ViewBag-and-TempData-MVC-Option).

I would suggest to try using the ViewBag to prove this theory. If it proves out you might think about passing this data as part of a complex object instead of using MVC's data dictionaries.

like image 121
John Meyer Avatar answered Nov 06 '22 03:11

John Meyer