I'm trying to create a new Salesman with Angular and C#. From Angular i collect the data the user has typed into an array (newData) and sending it from my controller --> service to my C# controller server-side. But i get several errors and it can't get my object.
Angular controller:
$scope.addSalesman = function (newData) {
myService.addNewSalesman(newData).then(function (data) {
console.log(data);
}, function (err) {
console.log(err);
});
};
Angular service:
addNewSalesman: function (newData) {
var deferred = $q.defer();
$http({
method: 'POST',
url: '/api/Salesman',
headers: { 'Content-type': 'application/json' }
}, newData).then(function (res) {
deferred.resolve(res.data);
}, function (res) {
deferred.reject(res);
});
return deferred.promise;
}
C# controller:
public HttpResponseMessage Post([FromBody] newData newdata) {
return Request.CreateResponse(HttpStatusCode.OK);
}
My errors are on the C# controller:
The type or namespace "newData" could not be found
"HttpRequest" does not contain a definition for "CreateResponse" accepting first argument of type "HttpRequest"
I tried adding the using System.Net.Http; and using System.Net; but doesn't work. Any suggestions?