1

在此处输入图像描述

我想在单击取消按钮时取消文件上传。

表示我想在单击取消按钮时触发onCancel(e)事件

我的代码是,

 @(Html.Kendo().Upload()
  .Name("files")
   .Multiple(false)
   .Async(a => a
    .Save("UploadArtifactFile", "PP", new { TeacherEvalID = ViewBag.TeacherEvalID, ObservationID = ViewBag.ObservationID, Accountid = ViewBag.AccountID })
    .AutoUpload(false)
    .RemoveField("")
     )
    .Events(events => events
    .Success("onSuccess")
    .Select("onSelect")
    .Error("onUploadError")
    .Upload("onUpload")
     .Cancel("onCancel")
     .Remove("onRemove")
      )

   On cancel event is work as expected,  

function onCancel(e) {
        //Array with information about the uploaded files
        var files = e.files;
        e.preventDefault();
    }

我想为取消按钮做同样的事情,点击取消按钮我写了代码,

function setNewArtifact() {
        var upload = $("#files").data("kendoUpload");
        //detach events and prepare for safe removal
        //upload.destroy();

        $(".k-upload-files.k-reset").find("li").remove();
        $('#lblArtifactFileName').val("");
        $('#lblArtifactFileName').hide();
        //hdnArtifactUploadIsAddOrEdit :1 for new artifact (Add)
        $('#hdnArtifactUploadIsAddOrEdit').val("1");
        $('#txtArtifactDescription').val("");
        $('#lblArtifactFileName').hide();
        $('#btnModifyArtifact').css("display", "none");
        $('.k-upload-selected').css("display", "none");

        //on click of cancel hide the uploading and uploaded status
        $(".k-dropzone").find("strong").css("display","none");
        $(".k-upload-status.k-upload-status-total").find("span").css("display","none");

        $.extend(upload.options.localization, {
            headerStatusUploading: "",
            headerStatusUploaded: ""
        });

    }

有什么办法可以做到这一点?

请帮忙...

4

1 回答 1

2

您可以触发上传取消事件:

$(document).ready(function() {
  $("#files").kendoUpload({
    async: {
      saveUrl: "save",
      removeUrl: "remove",
      autoUpload: true
    },
    cancel: function(e) {
      alert("cancel");
    }
  });

  $("#button").click(function(e) {
    $("#files").data("kendoUpload").trigger("cancel");	
  });
});
<input name="files" id="files" type="file" />
<button id="button">Cancel</button>

于 2015-03-20T06:50:54.187 回答