HttpPostedFileBase is null

7 posts, 0 answers
  1. Steven
    Steven avatar
    29 posts
    Member since:
    Jul 2012

    Posted 11 Oct 2012 Link to this post

    *** SOLUTION FOUND (see EDIT below) ***

    I have followed some of the examples for declaring my MVC controller method for use with the Upload component.  My upload handler declaration is as follows:

    public ActionResult Upload(IEnumerable<HttpPostedFileBase> attachments, long inventoryID, long imageType)
    {
    }

    I have set my Upload control to use Async.  However, whenever I try to upload a file, the attachments parameters is always passed null.

    I have also tried:
    • Renaming attachments to files
    • Declaring IEnumerable<HttpPostedFileBase> as IEnumerable<HttpPostedFile>
    • Declaring the attachments parameter as both HttpPostedFileBase and HttpPostedFile (singular

    I have written some JavaScript (as the Upload event) to pass the additional parameters (inventoryID and imageType) which are always passed successfully.

        function imageUploadUpload(e) {
            e.data = { inventoryID : @Model.InventoryID, imageType: imageType };
        }

    I have tried removing the Upload event/handler to see if this makes a difference, but still have the same problem.

    Any idea what is going on?

    Thank you.

    *** EDIT ***

    I found the solution here.  The name of the Upload component must match the name of the parameter that holds the HttpPostedFileBase.  I had named my Upload component imageUpload.  When I renamed the parameter to imageUpload, it worked fine!


  2. Bill
    Bill avatar
    75 posts
    Member since:
    Feb 2013

    Posted 12 Jun 2013 Link to this post

    I ran into this exact same issue.

    I can confirm that after naming the parameter in the controller the exact same name as what I named the KendoUI upload control, it worked.  Thanks Steven.
  3. Soori
    Soori avatar
    7 posts
    Member since:
    Jun 2013

    Posted 06 Aug 2013 Link to this post

    Thanks. That solved my issue .
  4. Soori
    Soori avatar
    7 posts
    Member since:
    Jun 2013

    Posted 17 Mar 2014 in reply to Bill Link to this post

    Name attribute of the  KendoUI upload control should be same as the parameter name of Controller. In following example it is 'fille'

    <input name="file" id="fileUploader" type="file" />


     public ActionResult UploadFile(HttpPostedFileBase file, String subject, String doc, String ref)
    {
    }
  5. elke
    elke avatar
    4 posts
    Member since:
    Jan 2017

    Posted 10 Feb in reply to Soori Link to this post

    that is a problem if you want to use the uploader in a patial view that is used in multiple tabs or pills on the same page.

    ex. i have a product "dress" and the dress had multiple "finishes", ex red, blue and yellow.

    i made tabs per finish and now i want to upload picuters on differet tabs.

    my uploader requires a unique identifier per tab, so it's called "uploader_blue", "uploader_red",... 

    however, the controler and the action is always the same. i cant make 5 actions with the same name and different parameters.......

     

  6. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2213 posts

    Posted 10 Feb Link to this post

    Hello elke,

    In such cases you should use the async.saveField configuration option and specify it to match the name of the controller action parameter. This will allow you to keep the different names of the uploads.

    Regards,
    Dimiter Madjarov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  7. Attila
    Attila avatar
    18 posts
    Member since:
    Oct 2016

    Posted 28 Sep in reply to Steven Link to this post

    Goddamnit!!! After debugging for hours this saved my evening! Thanks a lot buddy, it worked for me too!
Back to Top