Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 120 posts 448 karma points
    Sep 30, 2014 @ 10:25
    Tom
    0

    Doing $http.post from angular to web api

    Hi

    I'm trying to get a $http.post call going from angular but is getting an 404.

    If I convert it to a Get it works fine. What am I doing wrong?

    Here is my js

       angular.module('umbraco.resources').factory('migrationResource', function ($q, $http) {
            return {
                migrateFiles: function (subnetId) {
    
                    return $http({
                        method: 'POST',
                        url: 'DBU/DBUApi/MigrateFiles',
                        data: "SubnetId=" + subnetId                    
                    });
    
        //I've also tried this
        //return $http.post("DBU/DBUApi/MigrateFiles", { params: { SubnetId: subnetId } });
    
                    }           
            };
        }
    );
    

    And here is my webapi function

     [System.Web.Http.HttpPost]  
        public int MigrateFiles(int SubnetId)
        {
            //bla bla....
            return 1;
        }
    
  • Paul Sørensen 304 posts 650 karma points
    Apr 05, 2016 @ 16:27
    Paul Sørensen
    1

    Hi

    change to this [FromBody]int SubnetId

    /Paul S

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies