2017-06-21 8 views
1

こんにちは、私はWeb APIアプリケーションで角度を開発しています。私は角度から配列を持つオブジェクトを受け取ろうとしています。残念ながら私はnullを配列に受け取りました。私はリクエストオブジェクトの上に送信すると、私はテンプレートでnullを受け取ることになりますクラスangularjsはネストされたオブジェクトをAPIに送信します

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; } 
     } 

の下に持っているウェブAPIでは

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; 
} 

public HttpResponseMessage Put(int id, updatercvparams obj) 

ここでは何も分かりませんか?

答えて

1

templatesを配列として定義したので、オブジェクトではなく配列を送信する必要があります。

var sub = { 
    projectId: "50", 
    code: "app", 
    templates: [{ 
     .... 
    }] 
}; 
+0

感謝。出来た... –

1

ウェブAPIのエンティティ(クラス)ごとに、フィールド名はjavascriptオブジェクト内で同じである必要があります。配列のようなデータのリストを送信している間は、角括弧( '[]')を使用します。

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; 
 
}

関連する問題