我需要从视图向控制器发送一个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)
{
}
我甚至试图将数据作为对象并投射它但是它不起作用。
答案 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') }
);