2016-06-30 7 views
0

したがって、私はangularJS配列を持ち、ASP.Net MVCメソッドに渡し、そのデータをデータベースに格納したいと考えています。anglejs配列をASP.Net MVCメソッドに渡す

配列は、以下のようになります。

telephone = [{'id':'T1', 'contactN':'212-289-3824'}, {'id':'T2', 'contactN':'212-465-1290'}];

私はボタンをクリックすると、それは以下のJS機能を起動:

$scope.updateUserContacts = function() { 
    $http.post('/Home/UpdateUserContacts', { contactsData: $scope.telephone }) 
     .then(function (response) { 
      $scope.users = response.data; 
     }) 
    .catch(function (e) { 
     console.log("error", e); 
     throw e; 
    }) 
    .finally(function() { 
     console.log("This finally block"); 
    }); 
} 

私の質問は、私はこれを受け取ることができるか、です私のASP.Net MVCの配列?この配列と互換性のあるフォーマットは何ですか?

以下はASP.Net MVCメソッドの例ですが、渡された配列を受け取るタイプと受け取り方法はわかりません。

[HttpPost] //it means this method will only be activated in the post event 
    public JsonResult UpdateUserContacts(??? the received array) 
    { 
     ...... 
} 

答えて

1

タイプListまたは

[HttpPost] //it means this method will only be activated in the post event 
    public JsonResult UpdateUserContacts(List<MyObj> contactsData) 
    { 
     ...... 
    } 

OR

public JsonResult UpdateUserContacts(MyObj[] contactsData) 
    { 
     ...... 
    } 

Arrayする必要がありますそして、あなたはあなたのMVCアプリケーションシートでは、この

public class MyObj 
{ 
    public string id {get;set;} 
    public string contactN {get;set;} 
} 
2

のようなモデルクラスを持つべきですあなたは電話クラスを持っている必要があります

class Telephone 
{ 
    public string id; 
    public string contactN; 
} 

[HttpPost] //it means this method will only be activated in the post event 
public JsonResult UpdateUserContacts(Telephone[] contactsData) 
{ 
     //Do something... 
} 
関連する問題