Asp.net 对象在使用$resource传递给angularjs中的服务时为null
我从最近几个小时开始一直在做这个,但没有上路。谢谢你提前提供的帮助 我的合同代码:Asp.net 对象在使用$resource传递给angularjs中的服务时为null,asp.net,angularjs,Asp.net,Angularjs,我从最近几个小时开始一直在做这个,但没有上路。谢谢你提前提供的帮助 我的合同代码: [WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Employee", BodyStyle = WebMessageBodyStyle.Wrapped)] [OperationContract] void PutEmployeeAccount(Employee obj); 我的服务代码 public
[WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Employee", BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract]
void PutEmployeeAccount(Employee obj);
我的服务代码
public void PutEmployeeAccount(Employee obj)
{
// obj passed is null
}
我的AngularJS代码
var myApp = angular.module('myApp', ['ngResource']);
myApp.factory('resourceService', function ($resource) {
var src = $resource("../EmployeeService.svc/Employee/:id",
{ id: "@id" }, //parameters default
{
GetData: { method: "GET", params: {}, isArray: true },
GetDataById: { method: "GET", params: { id: 0 }, isArray: true },
Delete: { method: "DELETE", params: { id: 0 }, isArray: true },
Update: { method: "PUT", params: {}, isArray: true },
save: { method: "PUT", params: {}, isArray: false }
});
return src;
});
function EmployeeCtrl($scope, resourceService) {
var Employee = new resourceService();
Employee.Employeename = 'bar';
Employee.$save();
}
PutEmployeeAccount可以调用web服务。但传递的employee对象为null
如何解决此问题。通过点击和试用解决问题,设置BodyStyle=WebMessageBodyStyle.Bare已解决此问题。对您有好处!你也可以接受自己的答案,让别人看到问题已经解决。