0

我按照MVC4 音乐商店教程制作购物卡。不幸的是,当我使用 RemoveFromCard 函数时,我收到以下消息:

The resource cannot be found. 
  Description: HTTP 404. The resource you are looking for (or one of its  
  dependencies) could have been removed, had its name changed, or is temporarily   
  unavailable. Please review the following URL and make sure that it is spelled 
  correctly. 

Requested URL: /ShoppingCart/RemoveFromCart/1

我在查看页面上使用的代码如下:

<script src="/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        // Document.ready -> link up remove event handler
        $(".RemoveLink").click(function () {
            // Get the id from the link
            var recordToDelete = $(this).attr("data-id");
            if (recordToDelete != '') {
                // Perform the ajax post
                $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
                function (data) {
                    // Successful requests get here
                    // Update the page elements
                    if (data.ItemCount == 0) {
                        $('#row-' + data.DeleteId).fadeOut('slow');
                    }
                    else {
                         $('#item-count-' + data.DeleteId).text(data.ItemCount);
                    }

                    $('#cart-total').text(data.CartTotal);
                    $('#update-message').text(data.Message);
                    $('#cart-status').text('Cart (' + data.CartCount + ')');
                });
            }
        });
    });

</script>

使用以下操作链接:

<td>
                <%: Ajax.ActionLink("Remove from cart", "RemoveFromCart",
                        new { id = item.RecordId },
                        new AjaxOptions { OnSuccess = "handleUpdate" })%>
            </td>

此外,

我在 ShoppingCard.cs 中有这个方法

public int RemoveFromCart(int id) //code

为什么找不到这个方法?我将非常感谢一些帮助!

4

1 回答 1

0

好的,我解决了问题...我将操作链接更改为:

<a href="#" class="RemoveLink" data-id="<%:item.RecordId %>">Remove from cart</a>

现在它正在工作。

于 2013-10-30T16:28:48.173 回答