I am encountering an issue with a JavaScript object in my application that contains an array object, which is a collection of objects with two properties (Name, Value) on the server-side.
Despite my efforts, when the code reaches the C# web service, the CustomProperties object is an array of 4 objects, but each Name and Value property is null.
myObject.CustomProperties = [];
myObject.CustomProperties.push({ Name: "FirstName", Value: $scope.userInfo.FirstName });
myObject.CustomProperties.push({ Name: "LastName", Value: $scope.userInfo.LastName });
myObject.CustomProperties.push({ Name: "Email", Value: $scope.userInfo.Email });
myObject.CustomProperties.push({ Name: "PortalId", Value: portalId });
I have also attempted the following...
myObject.CustomProperties = [];
myObject.CustomProperties.push({ "Name": "FirstName", "Value": $scope.userInfo.FirstName });
myObject.CustomProperties.push({ "Name": "LastName", "Value": $scope.userInfo.LastName });
myObject.CustomProperties.push({ "Name": "Email", "Value": $scope.userInfo.Email });
myObject.CustomProperties.push({ "Name": "PortalId", "Value": portalId });
Although all variables have values in the debugger, the array is not loading correctly, resulting in the web service showing null values.
https://i.sstatic.net/3a1zT.png
Below is the code that invokes the web service. I have removed what I believe to be unnecessary parts.
factory.callPostService("ActionName", myObject)
.success(function (data) {
// nothing happens inside this block
})
.error(function (data, status) {
// this block always executes
$scope.HasErrors = true;
console.log("Unknown error occurred calling ActionName");
console.log(data);
});
The server-side code I am using closely resembles my other classes and properties.
Here is the property declaration for the CustomProperties in myObject.
public List<CustomPropertyInfo> CustomProperties { get; set; }
And here is the CustomPropertyInfo class.
[Serializable]
public class CustomPropertyInfo : ICustomPropertyInfo
{
public string Name { get; set; }
public string Value { get; set; }
}