c# - Model from AngularJS to ASP.NET MVC5 -


I have some problems posting my controller to angular. If I post variables separately, then everything is fine But when I add my wires to an object that responds to my visual model, it only recognizes the ID but my PlayerViewModel is not in the list.

My visual models: < / P>

  View public class player modell {public entry ID (Received) Switch to); Set; } Public string name {get; Set; }} Public Squared TeamViewModel {public int id {get; Set; } Public listing & lt; View PlayerModel & gt; Players; } This is my MVC-controller:  
  [http post] Public JS not included index (int id, list and lieutenant; playerviewmodel> listplarer, TeamViewModal Team) {return Jason (true, Jesenfesti Bihari. Elovaget); }  

This is my angular code:

  $ scope.players = []; $ Scope Player A = {ID: 5, Name: "Player 1"}; $ Scope Playerb = {id: 6, name: "player2"}; $ Scope.playerC = {ID: 8, name: "Player 3"}; $ Scope.players.push ($ scope.playerA); $ Scope.players.push ($ scope.playerB); $ Scope.players.push ($ scope.playerC); $ Scope.ID = 7; $ Scope.team = {ID: $ scope.ID, player: $ scope.players}; $ Scope.btnClick.btnClick = function () {$ http ({Traditional: true, url: "IndexPost", Method: "POST", Data: {'id': $ scope.ID, 'ListPlayers': $ scope Players, success (work (data) {$ scope.finish = data;}) error (function (data) {$ scope.status = status;}); 'team': $ scope.team}, data type: formdata }). }  

This is my response to the controller:

As you can see, the ID of my team vivodal is correct, but the list The player's view will not be filled in the model. Does anyone have an idea that what I'm doing is wrong?

Thank you!

serialize your data

  var data = JSON.stringify ({'Id': $ scope.ID, 'listplayer': $ scope.players, 'team': $ scope.team});  

In your original code, you set a JS object in the data to send, by serializing it, you send the data as JSON, which your server can read.


Comments