开发者

Drag and Drop not dropping in 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?

            $("#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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜