Reputation: 704
Using angular, I send an HTTP request
$scope.addFiles = function (files) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
$http.post('/api/files/addFiles', JSON.stringify({ testName: "test", someRandomCrap:"asdf"}));
}
}
I receive the request properly in my controller. However, the response is null:
After verifying that the content header is alright and the information was actually sent, I replaced the sample object with a generic object:
Lo and behold. It works! From this, my guess is that Web API could not bind to my object. Which brings me to my question: What does Web API need to bind to an object?
TestObject:
public class TestObject
{
string testName { get; set; }
string someRandomCrap { get; set; }
}
Upvotes: 3
Views: 99
Reputation: 48972
Try this:
$scope.addFiles = function (files) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
$http.post('/api/files/addFiles', { testName: "test", someRandomCrap:"asdf"});
}
}
Two things:
JSON.stringify
otherwise it will treat your whole object as a string. In your second picture, the fileName
is of type string Also try making your properties public:
public class TestObject
{
public string testName { get; set; }
public string someRandomCrap { get; set; }
}
Upvotes: 2
Reputation: 6839
Just need the object Itself:
$scope.addFiles = function (files) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
$http.post('/api/files/addFiles',{ fileName: { testName: "test", someRandomCrap:"asdf"}});
}
}
Upvotes: 0