1

Hi I am developing angular with web API application. I am trying receive object with array from angular. Unfortunately I am receiving null in the array.

this.updateprocesswithtemplates = function () {
    var sub = {
        projectId: "50",
        code: "app",
        templates: {
            title: "templatetiltle",
            version: "templateversion",
            visible: "templatevisible",
            templatefileid: "31",
            displayorder: "1"
        }
    };
    var responseservice = $http.put('/api/processes/81/', sub).success(function (response) {});
    return responseservice;
}

In web API i have below class

  public class updatercvparams
        {
           public string projectId{ get; set; }
           public int code { get; set; }
           public templates[] templates { get; set; }
        }
 public class templates
        {
            public string title { get; set; }
            public string version { get; set; }
            public int displayorder { get; set; }
            public string visibility { get; set; }
            public int templatefileid { get; set; }
        }

When I send above request object I will receive null in templates.

 public HttpResponseMessage Put(int id, updatercvparams obj)

May I know, Am I missing anything here?

2 Answers 2

1

As you have defined templates as an array, you need to send an array not a object.

var sub = {
    projectId: "50",
    code: "app",
    templates: [{
        ....
    }]
};
Sign up to request clarification or add additional context in comments.

Comments

1

As per your entity(class) in web api, field name should be same in javascript object. While you sending list of data like array, use square bracts('[]').

this.updateprocesswithtemplates = function() {
  var sub = {
    projectId: "50",
    code: "app",
    templates: [{
      title: "templatetiltle",
      version: "templateversion",
      visibility: "templatevisible",
      templatefileid: "31",
      displayorder: "1"
    }]
  };
  var responseservice = $http.put('/api/processes/81/', JSON.stringify(sub))
    .success(function(response) {});
  return responseservice;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.