我想将一些数据(guid)传递给kendoUpload的上载方法,以便特定的MVC Controller操作方法将接收该数据。每次上载时,我都需要传递此数据(引导)。
$("#propertyAttachmentUpload").kendoUpload({
async: {
saveUrl: fileUploadUrl,
chunkSize: 1048576,
removeUrl: "remove"
},
multiple: true,
upload: function (e) {
e.data = { id: $("#fileUplpderParentObjectId").val(), fileId: fileId };
},
showFileList: false,
dropZone: ".propertyAttachmentDropZone",
success: onSuccess
});
该字段为fileId
。我可以在上载按钮的click事件中调用上面的代码块,它可以工作,但是Kendo UI样式在初始化时未应用于上载按钮。
$("#propertyAttachmentUpload").click(
function() {
var fileId = guid();
$("#propertyAttachmentUpload").kendoUpload({
async: {
saveUrl: fileUploadUrl,
chunkSize: 1048576,
removeUrl: "remove"
},
multiple: true,
upload: function (e) {
e.data = { id: $("#fileUplpderParentObjectId").val(), fileId: fileId };
},
showFileList: false,
dropZone: ".propertyAttachmentDropZone",
success: onSuccess
});
});
如何在不失去Kendo UI样式的情况下初始化fileId。
注意:我无法在guid()
方法内调用upload
,因为上载方法需要每个上载块。对于所有块,特定文件的fileId应该相同。
答案 0 :(得分:0)
我已经使用全局变量并在上传按钮的click事件中设置了该变量,从而解决了该问题,
var fileGuid = '';
$(document).on('click', '#propertyAttachmentUpload', function() {
fileGuid = "";
fileGuid = guid();
})
$("#propertyAttachmentUpload").kendoUpload({
async: {
saveUrl: fileUploadUrl,
chunkSize: 1048576,
removeUrl: "remove"
},
multiple: true,
upload: function (e) {
e.data = { id: $("#fileUplpderParentObjectId").val(), fileId: fileGuid };
},
showFileList: false,
dropZone: ".propertyAttachmentDropZone",
success: onSuccess
});