Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropzone with some other parameters

I upload image using Dropzone. I need to send some other values via that(Some text values).In my scenario i need to send Product Name to the controller(pls see some comment in code)

Image successfully comes to the Controller's side,when button click.

HTML Code :

<input type="text" name="text" id="txtprod" class="form-control" />

<div id="dropzonffe" style="width: 55%; margin-left: 25%">
    <form action="~/Admin/SaveProducts" class="dropzone" id="dropzoneJsForm"></form>
</div>

jQuery Code :

<script type="text/javascript">
Dropzone.options.dropzoneJsForm = {

    autoProcessQueue: false,
    init: function () {
        var submitButton = document.querySelector("#btnSubmit");
        var myDropzone = this;

        submitButton.addEventListener("click", function () {
            var ProductName = $("#txtprod").val();//<-- I want to send this Productname to the controller also.
            myDropzone.processQueue();
        });
    }
};
</script>

My Controller :

public ActionResult SaveProducts () {
    bool isSavedSuccessfully = false;

    foreach (string fileName in Request.Files) {
        HttpPostedFileBase file = Request.Files[fileName];
        isSavedSuccessfully = true;
    }
    return Json (new { isSavedSuccessfully, JsonRequestBehavior.AllowGet });
}

I need to pass the Product Name to the controller. How can I do it ?

like image 844
Alex Avatar asked Dec 15 '22 15:12

Alex


1 Answers

I found the solution to my problem.Here i have paste it for future help.There's a event in DropZone called sending.you can pass additional parameters via append to form data.

 Dropzone.options.dropzoneJsForm = {
    autoProcessQueue: false,
    init: function () {
        var submitButton = document.querySelector("#btnSubmit");
        var myDropzone = this;

        this.on("sending", function (file, xhr, formData) {
            formData.append("ProductName", $("#txtprod").val());


        });

        submitButton.addEventListener("click", function () {
        myDropzone.processQueue();

        });

    }
};

Access it in Server Side

 public ActionResult SaveProducts(string ProductName)
    {

     }
like image 134
Alex Avatar answered Dec 29 '22 12:12

Alex