-1

I am trying to do a $post call to an ASP.NET Folder that is inside my ASP.NET Project) and I keep getting these errors:

TypeError: $http.post(...).success is not a function

http://localhost/Uploads 405 (Method Not Allowed)

Here is my code:

var fd = new FormData();
        fd.append('file', file);
        console.log(file);
        console.log(fd);
        $http.post(uploadUrl, fd, {
            transformRequest: angular.identity,
            headers: { 'Content-Type': undefined }
        })
        .success(function () {
        })
        .error(function () {
        });

After doing some debugging, the file is not empty (its from input type file) uploadUrl is not empty (its http://localhost/Uploads) however my FormData is empty. What am I doing wrong? I am trying to upload a file via jquery to an ASP.NET Folder called Uploads.

user979331
  • 11,039
  • 73
  • 223
  • 418
  • 1
    The method is "POST". The response tells you the problem: `/Uploads` doesn't accept POST. You haven't posted the method definition and relevant attributes so we can't help you more. – ProgrammingLlama Nov 01 '17 at 04:13

1 Answers1

0

first, you need to setupa a Controller Action that takes a ViewModel parameter. Inside that action you'll have to take care of the file saving into disk etc. And for submitting or calling the action to upload file, take a look at this answer here. setup a ajax request with jQuery and setup appropriate Content-Type for it to work.

gadasadox
  • 109
  • 1
  • 9