我使用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个参数值。原因是什么,我该如何解决?
EDIT1
似乎从下拉列表中选择的值未绑定到变量。
答案 0 :(得分: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);
}
});
}});