I was using this post to help me upload files to my MVC controller. jQuery ajax upload file in asp.net mvc For some reason the controller is never getting called. I would comment on the link but I don't have enough points for stackoverflow to let me comment on stuff. My javascript code is below, besides for changing a few things to use jquery is should have the same functionality. Any ideas? If more information is needed, just comment and I'll add whatever else I can. Thanks!
Javascript:
$("#btnSubmit").click(function () {
var formdata = new FormData();
var fileInput = document.getElementById('fileInput');
formdata.append(fileInput.files[0].name, fileInput.files[0]);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/Index/Upload');
xhr.send(formdata);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText);
}
}
return false;
});
Edit: When looking at the console output on my browser I saw the it wasn't recognizing the action(Index) that I was putting in. It would recognize the controller(Upload) but I think that is because the current view was already in the controller. Any ideas how to fix the path input for the XMLHttpRequest?