MVC3 how to add dynamic values to shopping cart
I have been following a guide to create a shopping cart in MVC3.
http://开发者_如何转开发mvcmusicstore.codeplex.com/
What i would like to do is to add additional values to the page where a user can add to cart. I want the option to select qty and size.
@Html.ActionLink("Add to cart", "AddToCart",
"ShoppingCart", new { id = Model.Id }, "")
If a user changes the qty or size then the Model.ID value needs to be changed in this link. How do i refresh the page and do this dynamically?
In my current project, we have a quantity next to the "Add to Cart" button. When the "Add To Cart" button is clicked, I get the url, add the quantity to it, and then send an ajax request back to the server.
$('#AddToCartLink').click(function() {
var link = $(this).attr('href') + '?quantity=' + $(this).siblings('.Quantity').val();
$.ajax({
url: link,
type: "POST",
success: AddToCartSuccess,
error: AddToCartFailure
});
return false;
});
HTML for Add to Cart button and Quantity:
<div class="DetailAddToCart">
Qty:
<input type="text" value="1" class="Quantity" id="Quantity" />
<a id="AddToCartLink" href="@Url.Action("Add", "Cart", new {id = Model.EquipmentModelId})">
<img src="/Content/Images/add_to_cart.png"alt="Add to Cart" /></a>
</div>
精彩评论