I can drag the images of album art and they clone and go back to their original place when dropped away from the cart button, but when I drop it on the cart button it doesn't update the cart, it just goes back to its original state. Why is this occuring?
$("#droppable").droppable({
drop: function (event, ui) {
var AlbumToAdd = ui.draggable.data("id");
if (AlbumToAdd != '') {
// Perform the ajax post
$.post("/ShoppingCart/DragToCart", { "id": AlbumToAdd },
function (data) {
// Successful requests get here
// Update the page elements
$('#cart-status').text("Cart (" + data.CartCount + ")");
});
}
}
});
Controller
//
// GET: /Store/DragToCart/5
public ActionResult DragToCart(int id)
{
// Retrieve the album fr开发者_StackOverflow社区om the database
var addedAlbum = storeDB.Albums
.Single(album => album.AlbumId == id);
// Add it to the shopping cart
var cart = ShoppingCart.GetCart(this.HttpContext);
cart.AddToCart(addedAlbum);
var results = new DragToCartViewModel
{
Message = Server.HtmlEncode(addedAlbum.Title) +
"Your cart has been updated",
CartTotal = cart.GetTotal(),
CartCount = cart.GetCount(),
AddedId = id
};
return Json(results);
Comment if you want to see more code.
精彩评论