Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 发送列表<;运费>;使用AngularJS在ASP.net MVC中创建控制器_Asp.net Mvc_Json_Angularjs - Fatal编程技术网

Asp.net mvc 发送列表<;运费>;使用AngularJS在ASP.net MVC中创建控制器

Asp.net mvc 发送列表<;运费>;使用AngularJS在ASP.net MVC中创建控制器,asp.net-mvc,json,angularjs,Asp.net Mvc,Json,Angularjs,我需要从视图向控制器发送一个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 D

我需要从视图向控制器发送一个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; }
}
我尝试了以下方法,但没有成功

// _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') }
 );
我需要发送
列表
,该列表存储在
货物
中的以下代码中

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

public JsonResult FreightItems_update(List<Freights> Freights, Guid CustomerGuid)
{
}
public JsonResult-FreightItems\u更新(列出货物,Guid CustomerGuid)
{
}
我甚至尝试将数据作为对象进行转换,但没有成功

// _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') }
     );

如何在action方法中访问myObject?您的操作“FreightItems\u update”将识别myObject包含Freights和CustomerGuid,因此您不必担心myObject您可以在操作中访问Freights和CustomerGuid我的问题是,当我们发送参数时,您使用这些变量,这里我如何使用myObject?@RandomUser myObject是您数据的唯一包装器。如果您愿意,您可以使用选项2。如果我是哑巴,请原谅我,但我需要知道如何在控制器中使用
myObject
,例如,在我的问题中,假设我确实按预期获得了列表,我会将其用作
货运[0].Name
在操作方法中。