使用AngularJS </freight>将列表<freight>发送到ASP.net MVC中的控制器

时间:2014-07-30 07:12:49

标签: asp.net-mvc json angularjs

我需要从视图向控制器发送一个List<Freight>的JSON对象。

我该怎么办呢。

课程是:

public class Freights
{
    public string Name { get; set; }
    public string ListName { get; set; }
    public decimal Price { get; set; }
    public decimal PostPaidCost { get; set; }
    public string DisplayPrice { get; set; }
    public bool Active { get; set; }
    public string Description { get; set; }
    public string Transport { get; set; }
    public string Instance { get; set; }
}

我尝试了以下但是没有用。

我需要将List<Freights>中存储的Freights发送到以下代码中。

$http.post('/Customization/FreightItems_update?Freights=' 
     + Freights + '&CustomerGuid=' + CustomerGuid).success(function (result) {
        ...
});

控制器:

public JsonResult FreightItems_update(List<Freights> Freights, Guid CustomerGuid)
{
}

我甚至试图将数据作为对象并投射它但是它不起作用。

1 个答案:

答案 0 :(得分:1)

// _Freights =  aray of Freights 
//_CustomerGuid = CustomerGuid

var myObject =  {
                          Freights: _Freights,
                          CustomerGuid: _CustomerGuid                            
                        };

 $http.post('/Customization/FreightItems_update', myObject)
        .then(
          function () { alert('ok')}
        , function () {alert('can't post') }
 );

选项2

 $http.post('/Customization/FreightItems_update',
 {Freights: _Freights,  CustomerGuid: _CustomerGuid})
            .then(
              function () { alert('ok')}
            , function () {alert('can't post') }
     );