dimanche 28 juin 2015

Passing multiple JSON ("rows" or object) to a Controller

var POS = {
        AddItem: function (SKU) {
            $.ajax({
                type: 'POST',
                data: '{"code":"itm-0008", "qty":"5"},
                       {"code":"itm-0009", "qty":"1"},
                       {"code":"l1", "qty":"8"}',
                url: '@Url.Action("AddProduct", "POS")',
                success: function (data) {
                   alert("Items Successfully Added!");
                },
                error: function (req, status, errorObj) {
                    alert(errorObj.toString());
                }
            });
        }
};

This is my Controller: (It can only handle one(1) JSON "row" or object)

    [HttpPost]
    public void AddProduct(Item items)
    {
        Inventory inv = new Inventory();

        inv.Add(items.code, items.qty);
        inv.Dispose();
    }

How can i pass this multiple JSON "row" or object to a Controller?

Aucun commentaire:

Enregistrer un commentaire