Reputation: 3023
Just started using Dropzone and so far it looks really good. I have the backend-functionality to handle the upload itself, but when debugging I've noticed that the action never gets hit. This is due to the fact that my form includes a hidden input to pass along a required id (for the action that does the uploading). This is my form:
@using (Html.BeginForm("UploadFile", "UnitSummary", FormMethod.Post, new
{
enctype = "multipart/form-data",
id = "imgUpload",
@class = "dropzone"
}))
{
<div class="fallback">
<input name="file" type="file" multiple />
<input type="submit" value="Upload" />
<input type="hidden" name="unitId" value="@Model.ViewUnitContract.Id"/>
</div>
}
JS:
<script type="text/javascript">
$(document).ready(function () {
// Dropzone
Dropzone.options.imgUpload = {
paramName: "file", // Must match the name of the HttpPostedFileBase argument that the Upload action expects.
acceptedFiles: "image/*" // Accept images only
};
});
</script>
And here's my action:
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase file, int unitId)
{
...
}
Now, if I remove the "int unitId" parameter, this action triggered. The only problem is that I actually need that id :)
Upvotes: 3
Views: 3728
Reputation: 3023
Solved by using the following form:
<form action="/UnitSummary/[email protected]" class="dropzone" enctype="multipart/form-data" id="imgUpload" method="post">
<div class="fallback">
<input name="file" type="file" multiple />
<input type="submit" value="Upload" />
</div>
</form>
Controller action and js stayed the same.
Upvotes: 6