Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dropzone.js and ASP.NET MVC file posted is null?

I am trying to use dropzone.js to upload images in my ASP.NET MVC app. I am able to set-up the dropzone programatically, click on it, select the image and when I click "Open" in the file dialog, the correct Action is hit in the controller. However, the HttpPostedFileBase always comes back as null so I can't do anything with the image. ON the client-side, however, it shows the image thumbnail correctly, eventhough I can't get it on the server side.

This is the HTML:

<div style="float:left;margin-right:2px;" id="mainImage">
    <img src="/images/AddImage_button.png" class="dz-message" />
</div>

This is the js code I call after the doc is ready:

var myDropzone = new Dropzone("div#mainImage", { url: "/Market/UploadImage" });

And this is the action call inside of the controller:

public ContentResult UploadImage(HttpPostedFileBase imageFile)
{

    if (imageFile == null || imageFile.ContentLength == 0)
    {
    //.....
    }
}

The action is hit but imageFile is null. Does anyone has any ideas? By the way, the "dz-message" class was added in the image placeholder inside the dropzone because before that it was not clickable. I read it somewhere that was a fix for that issue and it worked.

Any ideas why I am getting null for imageFile?

like image 318
user2623997 Avatar asked Dec 07 '13 22:12

user2623997


1 Answers

Default parameter name that Dropzone uses is file, and yours is imageFile. Change imageFile to file and it will work

like image 50
Catalin Avatar answered Oct 01 '22 22:10

Catalin