我跟着MVC4 Music Store tutorial for making a shopping card。不幸的是,当我使用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
我在View页面上使用的代码如下:
<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>
使用以下actionlink:
<td>
<%: Ajax.ActionLink("Remove from cart", "RemoveFromCart",
new { id = item.RecordId },
new AjaxOptions { OnSuccess = "handleUpdate" })%>
</td>
此外,
我在ShoppingCard.cs中有这个方法
public int RemoveFromCart(int id) //code
为什么找不到这种方法?我会非常感谢你的帮助!
答案 0 :(得分:0)
好的,我解决了问题......我将actionlink更改为:
<a href="#" class="RemoveLink" data-id="<%:item.RecordId %>">Remove from cart</a>
现在它正在运作。