Frage

I am using telerik upload control for uploading the file.

@(Html.Telerik().Upload()
      .Name("fileUpload")
      .Multiple(false)
      .Async(async => async
      .AutoUpload(false))
      .ClientEvents(events => events))

I tried OnSelect FUnction

function onSelect(e) {
    var files = e.files;
    if (files[0].rawFile.size <= 0) {
        alert("File Size Can't be zero.");
        e.preventDefault();
    }
}

It is firing but giving an error in IE in mozilla firfor its working fine

Microsoft JScript runtime error: Unable to get value of the property 'size': object is null or undefined

It is uploading the file, but the problem is, it is accepting zero size file as well, I want validate that It should not accept zero size file. Some one please help me how to achieve that by jquery or if some other option is there is please let me know?

War es hilfreich?

Lösung

You can use ClientSide events to check the file and file size.

@(Html.Telerik().Upload()
    .Name("attachments")
    .Async(async => async
        .Save("Save", "Upload")
        .Remove("Remove", "Upload")
    )
    .ClientEvents(events => events
        .OnUpload("onUpload")
        )
     )
     function onUpload(e) {
          $console.log("Upload :: " + getFileInfo(e));
     }
     function getFileInfo(e) {
       return $.map(e.files, function(file) {
          var info = file.name;

          // File size is not available in all browsers
          if (file.size > 0) {
              info  += " (" + Math.ceil(file.size / 1024) + " KB)";
          }
          return info;
      }).join(", ");
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top