Drag and Drop not dropping into shopping cart
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?
$("#dr开发者_如何学编程oppable").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 from 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
Have you found out which part of the code doesn't work? Is it the droppable JS or the controller? If you put alert("blah"); in your JS you can find out which code doesn't get triggered.
精彩评论