How to pass a list of object for WEB API in angularjs

时间:2019-01-18 19:11:25

标签: angularjs

Hi i need to get input values from ng-repeat, i am having Item class like as follows

public class Item
{
    private String _DesignId;

    public String DesignId
    {
        get { return _DesignId; }
        set { _DesignId = value; }
    }
    private String _DesignName;

    public String DesignName
    {
        get { return _DesignName; }
        set { _DesignName = value; }
    }

    private String _Unit;

    public String Unit
    {
        get { return _Unit; }
        set { _Unit = value; }
    }

    private String _Price;

    public String Price
    {
        get { return _Price; }
        set { _Price = value; }
    }
}

Here my angularjs

 $scope.saveAllValues = function() {
   $scope.mylist = {};
   angular.forEach($scope.invoice.items , function(value, key){
   var objclsu = { 
   "DesignId" : value.DesignId,
   "DesignName" : $scope.ctrl.DesignName,
   "Unit" : value.unit,
   "Price" : value.price,
  };  
    $scope.mylist.push({objclsu});
});

Here I can not use push. objclsu is not an array. Here how to add objclsu into $scope.mylist.

Here my web method i am using generic list as a parameter

    [WebMethod()]
    public static void SaveList(List<Item> mylist)
    {  
    }


    var httpreq = { 
    method: 'POST', 
       url: 'Requirementapi/SaveList', 
   headers: { 'Content-Type': 'application/json; charset=utf-8', 'dataType': 'json' }, 
      data: { mylist : $scope.mylist } 
  } 
  $http(httpreq).success(function (response) { 
    callmsg(" invoice Saved successfully."); 
 });

0 个答案:

没有答案