我在模态窗口问题中有一个 kendoUpload 小部件 - 如果您关闭窗口然后再次打开它 kendoUpload 小部件,就好像它的某些部分创建了几个实例一样。因此,它会在您打开和关闭窗口时创建尽可能多的记录和上传。什么可能导致问题。每次关闭窗口但没有运气时,我都尝试销毁 kendoUpload 小部件。也许是因为语法错误......有什么想法吗?谢谢!
现在我再次关闭并打开模态窗口->
现在我尝试上传文件->
HTML:
<div id="UploadFiles" style="display: none">
<h3>Upload your files:</h3>
<div class="demo-section k-content">
<input name="files" id="files" type="file"/>
</div>
<br/>
<h3>Current files on server:</h3>
<div id="CurrentFilesOnServer">
<ul class="CurrentFilesOnServerList">
</ul>
</div>
模态窗口:
// Modal Window Upload file to server
var uploadFilesWindow = $("#UploadFiles").kendoWindow({
width: "350px",
modal: true,
title: "Upload file to server:",
actions: [
"Pin",
"Minimize",
"Maximize",
"Close"
],
close: function () {
}
}).data("kendoWindow");
JS 上传部分:
// upload file on server
$(".k-grid-upload")
.click(function () {
uploadFilesWindow.center().open();
function upload () {
$("#files")
.kendoUpload({
async: {
saveUrl: "/api/Grid/UploadFileOnServer",
removeUrl: "",
autoUpload: true
}
}
});
});
C#控制器:
// Upload file on server
public string UploadFileOnServer()
{
var file = HttpContext.Current.Request.Files.Count > 0 ?
HttpContext.Current.Request.Files[0] : null;
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(
HttpContext.Current.Server.MapPath("~/uploads"),
fileName
);
file.SaveAs(path);
}
return file != null ? "/uploads/" + file.FileName : null;
}