0

Following is the JQuery code that I'm using:

$('#btnVideoUpload').click(
    function () {
        var xhr = new XMLHttpRequest();
        var fd = new FormData();
        fd.append("AssociatedVideoFile", $('#AssociatedVideoFile')[0]);
        console.log($('#AssociatedVideoFile')[0]);
        xhr.open("POST", "/Admin/UploadVideo/", true);
        xhr.send(fd);
        xhr.addEventListener("load", function (event) {
            alert(event.target.response);
        }, false);
    });

Here is my controller code:

[HttpPost]
public void UploadVideo(HttpPostedFileBase AssociatedVideoFile){
    var fupVideoFile = AssociatedVideoFile;
    //other code...
}

When I run this code, the value of AssociatedVideoFile is always null. Can anyone help me with the issue and point out what I'm doing wrong?

randomstudious
  • 122
  • 2
  • 10
  • 1
    Try changing `$('#AssociatedVideoFile')[0]` to `$('#AssociatedVideoFile')[0].files[0]` or `$('#AssociatedVideoFile').prop('files')[0]` (also using `enctype="multipart/form-data"` on form tag). Probably you had mistakenly tried to get object array index instead of file array index from `"AssociatedVideoFile`. – Tetsuya Yamamoto Nov 16 '16 at 01:09
  • @Tetsuya Yamamoto: Got it working! I did not realize that I was trying to get the object array index. Thank you very much for pointing out! – randomstudious Nov 16 '16 at 15:00

0 Answers0