Javascript 服务器未映射到Asp.NET Web Api 2的带有Angular$resource的Post请求
我已经找到了$http服务的解决方案(它以JSON.stringify(…)的形式传递数据)。 但是我使用$resource进行查询,我还没有找到任何解决方案。Javascript 服务器未映射到Asp.NET Web Api 2的带有Angular$resource的Post请求,javascript,angularjs,json,asp.net-web-api,asp.net-web-api2,Javascript,Angularjs,Json,Asp.net Web Api,Asp.net Web Api2,我已经找到了$http服务的解决方案(它以JSON.stringify(…)的形式传递数据)。 但是我使用$resource进行查询,我还没有找到任何解决方案。 WebApi操作 角度分量 angular.module("owners").component("owners",{ templateUrl: '/angularjs-app/owners/owners.template.html', controller: ['Owner', function PhoneListCont
WebApi操作
角度分量
angular.module("owners").component("owners",{
templateUrl: '/angularjs-app/owners/owners.template.html',
controller: ['Owner',
function PhoneListController(Owner) {
this.AddNewOwnerAndRenew = function () {
Owner.save( { name: self.OwnerToAddName }//here data passed like JSON
,function () {
//some code in success function
});
}
}
]});
角度资源
angular.
module('owner.service').
factory('Owner', ['$resource',
function ($resource) {
return $resource('/api/home/owners');
}
]);
<input type="text" ng-model="$ctrl.OwnerToAddName" />
<input type="button" ng-click="$ctrl.AddNewOwnerAndRenew()" value="Add"/>
模板
angular.
module('owner.service').
factory('Owner', ['$resource',
function ($resource) {
return $resource('/api/home/owners');
}
]);
<input type="text" ng-model="$ctrl.OwnerToAddName" />
<input type="button" ng-click="$ctrl.AddNewOwnerAndRenew()" value="Add"/>
我试图通过JSON.stringify()
传递{name:self.OwnerToAddName}
,但没有帮助。你知道如何制作WebAPI映射对象吗