拖放不会掉进购物车

时间:2011-08-26 15:00:19

标签: javascript asp.net-mvc-3 jquery-ui drag-and-drop

我可以拖动专辑封面的图像,当他们从购物车按钮上掉落时,他们会克隆并回到原来的位置,但是当我将它放在购物车按钮上时,它不会更新购物车,它只会返回到原来的状态。为什么会这样?

            $("#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 + ")");
                            });
                    }
                }
            });

控制器

    //
    // 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);

评论是否要查看更多代码。

0 个答案:

没有答案