Reputation: 785
I have run into a wall, how does simplecart POST data? I have tried taking in a bunch of different data types and all I get is null.
JS for the simplecart setup:
<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>
My MVC Controller:
// POST: cart
[HttpPost]
public ActionResult cart(string contents)
{
var test = JsonConvert.DeserializeObject(contents);
return null;
}
Does anybody know how to fix this so it actually reads into the controller? I have tried making a model with the same data as the cart and still got null.
Upvotes: 0
Views: 187
Reputation: 785
I just needed a list of the variables that are sent by simplecart so I could use my controller properly.
I used a get call and then a Request.Form
call to find out the variables sent by SimpleCart.
Turns out I will need to use the request method mentioned above as simplecart just keeps tacking the items and all their details onto the end rather than using a JSON string or anything.
list is as follows, please note that items 6+ are repeated for as many items as you have:
I have answered my own question for the benefit of anyone else using simplecart.js in mvc, if anyone has a more elegant solution than using the request to get a variable number of post entries please post.
Upvotes: 0