0
我跟着MVC4 Music Store tutorial for making a shopping card。不幸的是,當我使用RemoveFromCard功能我得到以下信息:從卡中移除Ajax方法不適用於音樂商店購物卡的MVC4教程
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>
用下面的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
爲什麼找不到這種方法?我會非常感謝一些幫助!
你有[HttpPost]在你的方法之上? –
@MattBodily謝謝你,不,我沒有......但這並不能解決問題。 –