angularjs - ng-resource with custom object + Asp.net web api -
ng-resource - not able pass employee object web api
angularjs code
app.factory("entry", function ($resource) { return $resource("/api/emp/", { }, { "update": { method: "put" }, "reviews": { 'method': 'get', 'params': { "id": 1, 'name': "ram" }, isarray: true }, "updateemp": { 'method': 'get', 'params': { ng: '@id', id: '@id', employee: '@emp', status: '@status' }, isarray: true } } ); }); postdata = [{ "id": 1, "empname": "the hitchhiker's guide galaxy", "address": "douglas adams" }]; var ent = entry.updateemp({ ng: 1, id: 3, employee: json.stringify(postdata), status: 'test' });
web api method
here method:
public ihttpactionresult getemployee(int ng,int id, **employee employee**,string status) { }
can values except employee(getting null value).please advise.
you want send single employee, not array single instance.
try replacing this
postdata = { "id": 1, "empname": "the hitchhiker's guide galaxy", "address": "douglas adams" };
also updateemp
method expecting field called @emp
have called employee
. please update line following.
"updateemp": { 'method': 'get', 'params': { ng: '@id', id: '@id', employee: '@employee', status: '@status' }, isarray: true }
it useful open developer console (f12) in browser , have under network see xhr , make sure request formed correctly