I am trying to post data to my table (T-SQL/Azure) but all it writes is NULL and just one line, not even the complete array. I have tried numerous variations of the $param, serialize, $httpParamSerializer etc. none of them write the contents inside the table. Even tho the console.log tells me all is ok.
var data = $scope.test;
console.log(data);
var jsonData = angular.toJson(data);
console.log(jsonData)
var objectToSerialize = { 'object': jsonData };
console.log(objectToSerialize);
$http({
url: 'http://url/api/UserOrderProductList',
method: "POST",
data: $.param(objectToSerialize),
//data: $.param(data),
//data: $.param(jsonData),
//data: $httpParamSerializerJQLike(objectToSerialize),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
//headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
}).success(function (data) {
alert("done");
});
this is what i am writing:
var data = {
"quantity": 0,
"title": "string",
"imageFront": "string"
}
with the same matching table.
in the debugger is get the 201 created and the form-data of the complete array
Form Data from Headers:
object:[{"count":1,"title":"Lara croft",imageFront":"20170807234015"},
{"count":1,"title":"Dragon Age","imageFront":"20170807231312"},
{"count":2,"title":"Madden","imageFront":"20170807235148"}]
This is what is says in the Preview/Response:
{"id":16,"count":null,"imageFront":null,"title":null}
This is the backend section, how the request is recieved:
// POST: api/UserOrders
[ResponseType(typeof(UserOrderProductList))]
public async Task<IHttpActionResult> PostUserOrderProductList(UserOrderProductList UserOrderProductList)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.UserOrderProductLists.Add(UserOrderProductList);
await db.SaveChangesAsync();
return CreatedAtRoute("DefaultApi", new { id = UserOrderProductList.id }, UserOrderProductList);
}
what is going on and why does it all write NULL? When i am writing with swagger is all turns out fine.