【问题标题】:What format does simplecart POST data in? failing to get the POST data in MVC projectsimplecart POST 数据采用什么格式?无法在 MVC 项目中获取 POST 数据
【发布时间】:2016-10-07 04:56:14
【问题描述】:

我碰壁了,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;
    }

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

【问题讨论】:

  • 你有什么错误吗..你能在控制器中调试吗.....
  • 没有错误,对象作为 null 传入,如上所述。没有错误,正常进入控制器。
  • 使用 Html.BeginForm 参考:stackoverflow.com/questions/8356506/…
  • 据我所知,这不是 simplecart 的工作方式。

标签: c# asp.net-mvc simplecart


【解决方案1】:

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

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

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

列表如下,请注意第 6 条以上的条目重复出现的次数与您的条目一样多:

  1. 货币
  2. 运费
  3. 税
  4. 税率
  5. itemCount
  6. item_name_1
  7. item_quantity_1
  8. item_price_1
  9. item_options_1

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

【讨论】:

    猜你喜欢
    • 2020-04-02
    • 2015-10-22
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多