0

我碰壁了,simplecart 如何 POST 数据?我尝试过接受一堆不同的数据类型,但我得到的都是空的。

用于 simplecart 设置的 JS:

<script>
simpleCart({
currency: "AUD" // set the currency to pounds sterling
});

simpleCart({
    cartColumns: [
    { attr: "name" , label: "Name" } ,
    { attr: "size", label: "Size"},
    { attr: "price" , label: "Price", view: 'currency' } ,
    { view: "decrement" , label: false , text: "-" } ,
    { attr: "quantity" , label: "Qty" } ,
    { view: "increment" , label: false , text: "+" } ,
    { attr: "total" , label: "SubTotal", view: 'currency' } ,
    { view: "remove" , text: "Remove" , label: false }
    ]
});

simpleCart({
    checkout: {
        type: "SendForm",
        url: "umbraco/surface/cart/cart"
        }
    });
</script>

我的 MVC 控制器:

// POST: cart
    [HttpPost]
    public ActionResult cart(string contents)
    {
        var test = JsonConvert.DeserializeObject(contents);
        return null;
    }

有谁知道如何解决这个问题,所以它实际上读入控制器?我尝试使用与购物车相同的数据制作模型,但仍然为空。

4

1 回答 1

0

我只需要一个 simplecart 发送的变量列表,这样我就可以正确使用我的控制器。

我使用 get 调用,然后Request.Form调用来找出 SimpleCart 发送的变量。

事实证明,我需要使用上面提到的请求方法,因为 simplecart 只是不断地将项目及其所有详细信息添加到末尾,而不是使用 JSON 字符串或任何东西。

清单如下,请注意第 6 项以上的项目重复出现的次数与您拥有的项目一样多:

  1. 货币
  2. 航运
  3. 税率
  4. 项目计数
  5. item_name_1
  6. item_quantity_1
  7. item_price_1
  8. item_options_1

我已经回答了我自己的问题,以帮助其他在 mvc 中使用 simplecart.js 的人,如果有人有比使用请求获取可变数量的帖子条目更优雅的解决方案,请发布。

于 2016-10-07T07:06:43.393 回答