将动态值传递给valums上传中的其他参数

时间:2012-07-20 08:25:30

标签: javascript asp.net-mvc-3 file-upload

我正在使用valums上传文件插件与asp.net mvc 3.我有两个下拉框和一个ajax valums上传文件按钮。我在视图中有以下代码:

<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>

问题: 当我使用document.getElementByID传递valums上传函数的params属性值时,它总是取选择列表的第一个选项的值,即使我选择其他选项。我确信当第一次加载页面时它是值,即document.getElementById。如何获取当前选定的值并传递给上面代码中的params属性:

我的控制器操作如下:

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

2 个答案:

答案 0 :(得分:7)

您可以在提交其他值时使用setParams方法。

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

答案 1 :(得分:0)

它对我来说适用于2.0 beta版,如下所示:

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