I'm trying to pass complex objects from angular to a C# WebApi Controller. I have wrote this pointless code in order to learn.
JS code:
angular.module('app').controller('ExampleController', function($scope, $http) {
var self = this;
var obj = {
val1: {
val2: {
val3: true
}
}
};
self.exampleGet = function() {
$http.get('rest/myconso/exampleget', {
params: {
query: obj
}
}).then(function success(response) {
console.log('success');
}, function error(response) {
console.log('error');
});
};
self.examplePost = function() {
$http.post('rest/myconso/examplepost', obj).then(function success(response) {
console.log('success');
}, function error(response) {
console.log('error');
});
};
});
C# code:
public class ExampleController : ApiController
{
[Route("rest/myconso/examplepost")]
[HttpPost]
public IHttpActionResult ExamplePost(IDictionary<string, IDictionary<string, IDictionary<string, bool>>> query)
{
return Ok();
}
[Route("rest/myconso/exampleget")]
[HttpGet]
public IHttpActionResult ExampleGet([FromUri]IDictionary<string, IDictionary<string, IDictionary<string, bool>>> query)
{
return Ok();
}
}
The POST methods works perfectly as expected but not the GET method. The query parameter is always empty.
What is wrong with my code ?
Thanks