simplecart POST数据的格式是什么?无法获取MVC项目中的POST数据

时间:2016-10-07 04:56:15

标签: c# asp.net-mvc simplecart

我遇到过墙,simplecart POST数据怎么样?我试过接受一堆不同的数据类型,我得到的只是null。

JS用于simplecart设置:

<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;
    }

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

1 个答案:

答案 0 :(得分:0)

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

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

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

列表如下,请注意,项目6+将重复为您所拥有的项目:

  1. currency
  2. 航运
  3. TAXRATE
  4. ITEMCOUNT
  5. ITEM_NAME_1
  6. item_quantity_1
  7. ITEM_PRICE_1
  8. item_options_1
  9. 我已经回答了我自己的问题,为了mvc中使用simplecart.js的其他人的利益,如果有人有更优雅的解决方案而不是使用请求来获取可变数量的帖子条目请发布。