Search code examples
javascriptasp.net-web-apipolymerpolymer-1.0

Issue with iron-ajax element with body object Serialization


I'm facing a problem with the way that iron-ajax element is serializing an object.

I have a Web API method that is receiving as a parameter an Object with [FormBody] tag

public Post([FormBody] account obj){
    //....
}

The object account have the following structure:

String user;
String name;
List<permissions> permissions;

In my polymer project I have an element to save a form with this object, in my code I added programmatically the permission Object to an array in the following way:

for(...){
   this.account.permissions.push({permissionId: 1, accountId: 1, permissionValid: true});
}

After that I passed the object into the body property for the iron-ajax element. The problem is when I debugged the code in Visual Studio I got the object "account" with only one permission object inside and with no values in the attributes. I debugged the javascript object and at the moment where I execute: ironAjaxElement.generateRequest() the object "account" has five permissions objects. I checked also that all the attributes are well formed. Why is this happening?


Solution

  • I solved the problem changing the content-type property with: content-type="application/json"