如果文件太大,则在Kendo Upload中返回正确的错误消息

时间:2014-10-21 14:30:10

标签: c# asp.net-mvc kendo-ui kendo-upload

与Kendo上传有一些问题。当文件小于15MB的最大大小时,那很好。但是,如果它超过最大大小,则不会进入“上传”操作,但仍会返回“完成”消息。

 @(Html.Kendo().Upload()
    .Name("files")
    .ShowFileList(false)
    .Async(a => a.Save("Upload", "Document", new {@id = Model.ChangeRequestId})
        .AutoUpload(true))
    .Events(e => e
        .Complete("refreshFileList"))
    )

如果它进入操作,那么我将能够检查文件大小并返回适当的消息。 如果文件太大,有没有人设法成功处理Kendo上传的情况?

由于

1 个答案:

答案 0 :(得分:8)

为什么不在客户端进行文件大小验证呢?

使用upload事件检查大小并根据需要显示消息/中止下载。

.Events(e => e.Upload("onUpload"))
function onUpload(e) {
  var files = e.files;

  $.each(files, function () {
    if (this.size > 15*1024*1024) {
      alert(this.name + " is too big!");
      e.preventDefault(); // This cancels the upload for the file
    }
  });
}