0

我正在使用 jquery 上传文件并将三个参数传递给控制器​​。我可以传递 1 个参数,其他 2 个参数是从 Dropbox 中选择的。下拉框中的 2 个参数似乎未绑定到上传器的以下代码中

params: {fileType: @Model.fileType, employeeId: @Model.employeeId,  trainId: @Model.trainId },

下面是我上传文件的代码

<script type="text/javascript">

    window.onbeforeunload = function() {
        // This function does nothing.  It won't spawn a confirmation dialog   
        // But it will ensure that the page is not cached by the browser.
    }; 

    var button = $('#fileUpload')[0];
    var uploader = new qq.FileUploader({
        element: button,
        allowedExtensions: ['doc', 'docx', 'xls', 'xlsx', 'pdf'],
        sizeLimit: 2147483647, // max size
        action: '/Home/UploadFileToServer',
        multiple: false,
        params: {fileType: @Model.fileType, employeeId: @Model.employeeId,  trainId: @Model.trainId },
        onComplete: function(id, fileName, responseJSON) {
            $.ajax({
                url: "/Home/DetailsFiles",
                data: { id: @Model.employeeId },
                cache: false,
                dataType: "html",
                success: function(data) {
                    $("#employee_files").html(data);
                }
            });
        }});

我的视图模型如下:

 public int employeeId;
public int fileType;
public int trainId;
public File file;
public SelectList FileTypeList { get; set; }
public SelectList TrainingList { get; set; }

我的保管箱是:

<div id="trainFile">
        <div class="editor-label">
            Dosya Tipi
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.fileType, Model.FileTypeList)
        </div>
        <div class="editor-label">
            Eğitim
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.trainId, Model.TrainingList)
        </div>
    </div>

使用以下 div 上传文件:

<div id="fileUpload">
    <noscript>
        <p>
            Please enable JavaScript to use file uploader.</p>
        <!-- or put a simple form for upload here -->
    </noscript>
</div> 

我不明白为什么这些值没有绑定到模型属性。我在控制器上点击调试点,看到只传递了 1 个参数值。这是什么原因,我该如何解决这个问题?

编辑1

似乎从下拉列表中选择的值未绑定到变量。

4

1 回答 1

0

你没有在数据中传递其他参数,试试这个:

<script type="text/javascript">

window.onbeforeunload = function() {
    // This function does nothing.  It won't spawn a confirmation dialog   
    // But it will ensure that the page is not cached by the browser.
}; 

var button = $('#fileUpload')[0];
var uploader = new qq.FileUploader({
    element: button,
    allowedExtensions: ['doc', 'docx', 'xls', 'xlsx', 'pdf'],
    sizeLimit: 2147483647, // max size
    action: '/Home/UploadFileToServer',
    multiple: false,
    params: {fileType: @Model.fileType, employeeId: @Model.employeeId,  trainId: @Model.trainId },
    onComplete: function(id, fileName, responseJSON) {
        $.ajax({
            url: "/Home/DetailsFiles",
            data: { id: @Model.employeeId, fileType: @Model.fileType, traindID: @Model.trainId  },
            cache: false,
            dataType: "html",
            success: function(data) {
                $("#employee_files").html(data);
            }
        });
    }});
于 2013-06-13T09:26:26.790 回答