4

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

<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 传递值上传函数的参数属性中的值时,即使我选择其他选项,它也总是取选择列表的第一个选项的值。我确信在第一次加载页面时它是有价值的,即 document.getElementById。如何在上面的代码中获取当前选定的值并传递给 params 属性:

我有如下控制器操作:

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

2 回答 2

7

您可以在提交附加值时使用 setParams 方法。

var uploader = new qq.FileUploader({
    onSubmit: function() {
        uploader.setParams({
            anotherParam: 'value' 
        });
    }
});
于 2012-07-20T08:52:33.517 回答
0

它适用于我的 2.0 beta 版本,如下所示:

var uploader = new qq.FileUploader({
    ......
    onSubmit: function() {
        this.params.xyzfield='dummyval';
        ......
    }
});
于 2019-05-05T18:04:10.230 回答