控制器无法检索Ajax发布Json数组

时间:2017-03-21 17:26:58

标签: javascript c# asp.net json ajax

的Javascript

var poItemData = JSON.stringify(grid.getAll());
        poItemData = JSON.stringify({ 'poItemData': poItemData });
        alert(poItemData.toString());
        $.ajax({
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            type: 'POST',
            url: "@Url.Action("CreateOrUpdate2", "PurchaseOrder")",
            data: poItemData,
            success: function () {
                alert("Ok");
            },
            failure: function (response) {
                alert("!Ok");
            }
        });

发布Json

{"poItemData":"[{"id":3,"itemName":"Item 1","itemId":1,"poId":2,"quantity":100,"averageCost":100,"recordStatus":"O"},{"id":4,"itemName":"Item 2","itemId":2,"poId":2,"quantity":1000,"averageCost":10,"recordStatus":"O"}]"}

控制器

public IActionResult CreateOrUpdate2(List<PurchaseOrderItemList> poItemData)
    {
        return View();
    }

实体

public class PurchaseOrderItemList
{
    public int Id { get; set; }
    public string ItemName { get; set; }
    public int ItemId { get; set; }
    public int POId { get; set; }
    public decimal Quantity { get; set; }
    public decimal AverageCost { get; set; }
    public string RecordStatus { get; set; }
}

控制器未检索发布的Json。我想以列表的形式检索发布的结果。请帮忙解决

我的项目正在.net核心1.0.0框架上运行。

1 个答案:

答案 0 :(得分:0)

如某人已发布,请尝试

  county_choropleth(final, num_colors = 1) + 
  scale_fill_gradient2(c("red", "green", "blue", "yellow")[ceiling((0 : 60) / 10)], 
                       breaks = pretty(final$value, n = 5))

我会将方法签名更改为

formatedData = JSON.stringify(poItemData);
...
data: formatedData,

因为我不确定你是否可以直接在方法

中接收List实例