Search code examples
asp.netasp.net-mvcangularjsasp.net-mvc-4angular-resource

Resource Factory of Angular and ASP.NET MVC


I am calling resources from a ASP.MVC page http://host/Project/Index.cshtml to http://host/odata/ProjectAPI and so on.

Angular Factory works fine with first two functions getProject and postProject and send request to http://host/odata/ProjectAPI(:projectId value) and http://host/odata/ProjectAPI consequently.

But for some unknown reasons getMembers and postMember methods are sending request to http://host/Project/..odata/ProjectAPI(:projectId)/Members and http://host/Project/..odata/MemberAPI
Could anyone explain? PS: this requests are sent from same page but different tabs

app.factory('resourceProject', function ($resource) {

    return {

        getProject: function () {

            return $resource('../odata/ProjectAPI(:projectId)', { projectId: '@id' });
        },
        postProject: function () {

            return $resource('../odata/ProjectAPI');

        },
        getMembers: function () {
            return $resource('..odata/ProjectAPI(:projectId)/Members', { projectId: '@id' });

        },
        postMember: function () {
            return $resource('..odata/MemberAPI');

        }

    }


});

Solution

  • Your URL's are wrong:

    return $resource('..odata/ProjectAPI(:projectId)/Members'

    return $resource('..odata/MemberAPI');

    You've put .. instead of ../