Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
i have used plupload multiple file upload to upload files but when i click on save button it display null in HttpPostedFileBase FileData. please help me over it.


In View :
JavaScript
<link href="@Url.Content("~/Scripts/plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css")"
    rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Scripts/plupload/js/jquery.ui.plupload/css/jquery.ui.plupload.css")"
    rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/plupload/js/plupload.full.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/plupload/js/jquery.ui.plupload.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js")" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("#uploader").pluploadQueue({
            // General settings
            runtimes: 'html5,html4,gears,flash,silverlight',
            url: '@Url.Action("UploadImage")',
            max_file_size: '10mb',
            chunk_size: '1mb',
            unique_names: true,
            button_browse_hover: true,
            multiple_queues: true,
            dragdrop: false,

            // Resize images on clientside if we can
            resize: { width: 320, height: 340, quality: 90 },

            // Specify what files to browse for
            filters: [
            { title: "Image files", extensions: "jpg,gif,png,jpeg,bmp" },
            { title: "Zip files", extensions: "zip" },
            { title: 'PDF files', extensions: 'pdf' },
            { title: "Excel Files", extensions: "xls,xslx,csv" },

        ],



            // Silverlight settings
            silverlight_xap_url: '@Url.Content("~/Scripts/plupload/plupload.silverlight.xap")'
        });

        // Client side form validation
        $('form').submit(function (e) {

            var uploader = $('#uploader').pluploadQueue();
            // Files in queue upload them first
            if (uploader.files.length > 0) {

                if (uploader.files.length < 9) {
                    // When all files are uploaded submit form
                    uploader.bind('StateChanged', function () {
                        if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {

                            $('form')[1].submit();

                        }
                    });
                    uploader.start();
                } else {
                    alert('Number of files more than 8.');
                }
                return false;
            }
            else {
                alert('You must queue at least one file.');
            }
            return false;
        });



    });


</script>
<pre lang="HTML">@using (Html.BeginForm("ImageUpload", "Image", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div id="uploader">
        <p>
            You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
    </div>
    <p>
        <input type="submit" value="Save" id="uploadFile" name="uploadFile" />
    </p>



}




In controller :
C#
public ActionResult ImageUpload()
       {
           return View();
       }
       [HttpPost]
       public string ImageUpload(HttpPostedFileBase FileData)
       {

           FileData = Request.Files[0];
           if (FileData.ContentLength > 0)
           {
               var fileName = Path.GetFileName(FileData.FileName);
               var path = Path.Combine(Server.MapPath("~/Content"), fileName);
               FileData.SaveAs(path);
           }

           return "Files was uploaded successfully!";
       }
Posted

You should change your action result parameter same as the name attribute of file upload control like below.
C#
<input type="file" id="btnFile" name="uploadFile" />
<input type="submit" value="Save" id="btnSave" />
public string ImageUpload(HttpPostedFileBase uploadFile)


Hope this helps
 
Share this answer
 
v3
Comments
Member 7867386 21-Aug-13 7:14am    
I have changed HttpPostedFileBase FileData to HttpPostedFileBase uploadFile but still it has null into it.
Jameel VM 21-Aug-13 8:05am    
sorry i have make a mistake. I update my answer. Please try this
Member 7867386 22-Aug-13 0:42am    
i have not used input type ="file" because i am using jquery plupload file upload where there is no need to use file control.
Replace this url: '@Url.Action("UploadImage")', with
Quote:
url: '@Url.Action("ImageUpload")',
 
Share this answer
 
I had the same issue and it took me two days to solve it. This is what i did;
Include Controller and method at BeginForm

<!<%using (Html.BeginForm("ForexUpload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))%>
 
Share this answer
 
v2
Please follow below steps.

VB
Step 1: Open the view source of the page where you have file upload button.
Step 2: Check how many form tag you have.
Step 3: If you have more than one form tag, remove one and it will solve the issue.
Thanks,
Lijo
 
Share this answer
 
@using (Html.BeginForm("ActionMethod", "Controller", FormMethod.Post, new { enctype = "multipart/form-data" }))

Make sure you have enctype in the BeginForm
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900