Nightwalker83
Jul 2nd, 2011, 01:30 AM
Hi,
I finished my advanced C# case study for school although, when I click on either the "Create new" or "Remove from cart" links I receive the following error:
Server Error in '/' Application.
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/116
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225
I take it that the above message is referring to the ShoppingCartController and the "RemoveFormCart" is the method is is referring to? What about the 116? However, checking the "Controllers" folder there is a file called "ShoppingCartController.cs" it with a method RemoveFromCart inside the file.
//AJAX: /ShoppingCart/RemoveFromCart/5
[HttpPost]
public ActionResult RemoveFromCart(int id)
{
//Remove the item from the cart
var cart = ShoppingCart.GetCart(this.HttpContext);
//Get the name of album to display the confirmation
string albumName = StoreDB.Carts.Single(item => item.RecordId == id).Album.Title;
//Remove from cart. Removing all for simplicity
cart.RemoveFromCart(id);
//Display the confirmation message
var results = new ShoppingCartRemoveViewModel
{
Message = Server.HtmlEncode(albumName) + " has been removed from your shopping cart.",
CartTotal = cart.GetTotal(),
CartCount = cart.GetCount(),
DeleteId = id
};
return Json(results);
}
Here is the shoppingcart index page:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcMusicStore.ViewModels.ShoppingCartViewModel>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Shopping Cart
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function handleUpdate(context) {
//Load and deserialize the returned JSON data
var json = context.get_data();
var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
//Update the page elements
$('#row-' + data.DeleteId).fadeOut('slow');
$('#cart-status').text('Cart(' + data.CartCount + ')');
$('#update-message').text(data.Message);
$('#cart-total').text(data.CartTotal);
}
</script>
<h3><em>Review</em> Your cart:</h3>
<p class="button">
<%:Html.ActionLink("Checkout >>", "AddressAndPayment", "Checkout") %>
</p>
<div id="update-message"></div>
<table>
<tr>
<th>Album Name</th>
<th>Price (each)</th>
<th>Quantity</th>
<th></th>
</tr>
<% var cart = (MvcMusicStore.ViewModels.ShoppingCartViewModel)ViewData["cart"];
foreach (var item in cart.CartItems ) { %>
<tr id="row-<%: item.RecordId %>">
<td>
<%:Html.ActionLink(item.Album.Title, "Details", "Store", new { id = item.AlbumId}, null)%>
</td>
<td>
<%:item.Album.Price %>
</td>
<td>
<%: item.Count %>
</td>
<td>
<%: Ajax.ActionLink("Remove from cart", "RemoveFromCart", new { id = item.RecordId }, new AjaxOptions { OnSuccess = "handelUpdate" })%>
</td>
</tr>
<% } %>
<tr>
<td>Total</td>
<td></td>
<td></td>
<td id="cart-total">
<%: cart.CartTotal %>
</td>
</tr>
</table>
<p>
<%: Html.ActionLink("Create New", "GetCart")%>
</p>
</asp:Content>
So what exactly is it saying it can not find and how do I fix it?
Thanks,
Nightwalker
I finished my advanced C# case study for school although, when I click on either the "Create new" or "Remove from cart" links I receive the following error:
Server Error in '/' Application.
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/116
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225
I take it that the above message is referring to the ShoppingCartController and the "RemoveFormCart" is the method is is referring to? What about the 116? However, checking the "Controllers" folder there is a file called "ShoppingCartController.cs" it with a method RemoveFromCart inside the file.
//AJAX: /ShoppingCart/RemoveFromCart/5
[HttpPost]
public ActionResult RemoveFromCart(int id)
{
//Remove the item from the cart
var cart = ShoppingCart.GetCart(this.HttpContext);
//Get the name of album to display the confirmation
string albumName = StoreDB.Carts.Single(item => item.RecordId == id).Album.Title;
//Remove from cart. Removing all for simplicity
cart.RemoveFromCart(id);
//Display the confirmation message
var results = new ShoppingCartRemoveViewModel
{
Message = Server.HtmlEncode(albumName) + " has been removed from your shopping cart.",
CartTotal = cart.GetTotal(),
CartCount = cart.GetCount(),
DeleteId = id
};
return Json(results);
}
Here is the shoppingcart index page:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcMusicStore.ViewModels.ShoppingCartViewModel>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Shopping Cart
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function handleUpdate(context) {
//Load and deserialize the returned JSON data
var json = context.get_data();
var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
//Update the page elements
$('#row-' + data.DeleteId).fadeOut('slow');
$('#cart-status').text('Cart(' + data.CartCount + ')');
$('#update-message').text(data.Message);
$('#cart-total').text(data.CartTotal);
}
</script>
<h3><em>Review</em> Your cart:</h3>
<p class="button">
<%:Html.ActionLink("Checkout >>", "AddressAndPayment", "Checkout") %>
</p>
<div id="update-message"></div>
<table>
<tr>
<th>Album Name</th>
<th>Price (each)</th>
<th>Quantity</th>
<th></th>
</tr>
<% var cart = (MvcMusicStore.ViewModels.ShoppingCartViewModel)ViewData["cart"];
foreach (var item in cart.CartItems ) { %>
<tr id="row-<%: item.RecordId %>">
<td>
<%:Html.ActionLink(item.Album.Title, "Details", "Store", new { id = item.AlbumId}, null)%>
</td>
<td>
<%:item.Album.Price %>
</td>
<td>
<%: item.Count %>
</td>
<td>
<%: Ajax.ActionLink("Remove from cart", "RemoveFromCart", new { id = item.RecordId }, new AjaxOptions { OnSuccess = "handelUpdate" })%>
</td>
</tr>
<% } %>
<tr>
<td>Total</td>
<td></td>
<td></td>
<td id="cart-total">
<%: cart.CartTotal %>
</td>
</tr>
</table>
<p>
<%: Html.ActionLink("Create New", "GetCart")%>
</p>
</asp:Content>
So what exactly is it saying it can not find and how do I fix it?
Thanks,
Nightwalker