4
votes

I am using valums upload file plugins with asp.net mvc 3. I have two dropdown box and one ajax valums upload files button. I have following codes in Views:

<link href="@Url.Content("~/Content/css/fileuploader.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Content/js/fileuploader.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.7.2.js")" type="text/javascript"></script>


@using (Html.BeginForm("Upload", "AjaxUpload", FormMethod.Post, new { name = "form1" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Upload Wav File</legend>
         <div class="editor-label">
           @Html.Label("Select Language")
        </div>
        <div>

          @Html.DropDownList("Language1", (SelectList)ViewBag.lang)
      </div>
         <div class="editor-label">
           @Html.Label("Select Category")
        </div>


      <div>
          @Html.DropDownList("ParentCategoryID", ViewBag.ParentCategoryID as SelectList) 
      </div>

      <div id="file-uploader">
    <noscript>
        <p>
            Please enable JavaScript to use file uploader.</p>
    </noscript>
</div>
    </fieldset>
}


<script type="text/javascript">


    var uploader = new qq.FileUploader
    ({
        element: document.getElementById('file-uploader'),
        params: {
            param1: document.getElementById("Language1").value,
            param2: document.getElementById("ParentCategoryID").value
        },
        action: '@Url.Action("upload")', // put here a path to your page to handle uploading
        allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'], // user this if you want to upload only pictures
        sizeLimit: 4000000, // max size, about 4MB
        minSizeLimit: 0, // min size
        debug: true
    });
</script>

Problems: When I passed the values in params attributes of valums upload function using document.getElementByID, it always take value of first option of select list even I select other option. I am sure that it's taking value when page is loaded first time which is document.getElementById. How can I get the current selected value and passed to params attributes in above code:

I have Controller action as below:

[HttpPost]
        public ActionResult Upload(HttpPostedFileBase qqfile, string param1, string param2)
        {
           ..............
        }
2

2 Answers

7
votes

You can use the setParams method when submitting additional values.

var uploader = new qq.FileUploader({
    onSubmit: function() {
        uploader.setParams({
            anotherParam: 'value' 
        });
    }
});
0
votes

It is working for me with version 2.0 beta as follow :

var uploader = new qq.FileUploader({
    ......
    onSubmit: function() {
        this.params.xyzfield='dummyval';
        ......
    }
});