[RESOLVED] What are those errors/How do I fix them
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.
asp Code:
//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:
asp Code:
<%@ 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
Re: What are those errors/How do I fix them
Can you post your routes table? Or, indeed, write a test that ensures that URL maps to the expected controller/action? Because you're not generating the link from the controller, it's probably a mismatch there.
Re: What are those errors/How do I fix them
I have attached my project to the first post so you can see all the errors.
Re: What are those errors/How do I fix them
Can't download the project for restrictions, but are you sure the RemoveFromCart controller has a corresponding view defined?
The only other problem I can think of right now is the path is incorrect. However I am assuming you have already checked it.
.
Re: What are those errors/How do I fix them
Well, I solved the above errors by rewriting the shopping cart index page. Although, now I have another problem:
Server Error in '/' Application.
The current request for action 'LogOn' on controller type 'AccountController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult LogOn(MvcMusicStore.Models.LogOnModel, System.String) on type MvcMusicStore.Controllers.AccountController
System.Web.Mvc.ActionResult Logon(MvcMusicStore.Models.LogOnModel, System.String) on type MvcMusicStore.Controllers.AccountController
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Reflection.AmbiguousMatchException: The current request for action 'LogOn' on controller type 'AccountController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult LogOn(MvcMusicStore.Models.LogOnModel, System.String) on type MvcMusicStore.Controllers.AccountController
System.Web.Mvc.ActionResult Logon(MvcMusicStore.Models.LogOnModel, System.String) on type MvcMusicStore.Controllers.AccountController
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[AmbiguousMatchException: The current request for action 'LogOn' on controller type 'AccountController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult LogOn(MvcMusicStore.Models.LogOnModel, System.String) on type MvcMusicStore.Controllers.AccountController
System.Web.Mvc.ActionResult Logon(MvcMusicStore.Models.LogOnModel, System.String) on type MvcMusicStore.Controllers.AccountController]
System.Web.Mvc.ActionMethodSelector.FindActionMethod(ControllerContext controllerContext, String actionName) +226
System.Web.Mvc.ReflectedControllerDescriptor.FindAction(ControllerContext controllerContext, String actionName) +182
System.Web.Mvc.ControllerActionInvoker.FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, String actionName) +47
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +283
System.Web.Mvc.Controller.ExecuteCore() +136
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +65
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8920029
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
when I try to login to the site.
Edit:
Never mind! I solved that problem too. I just copied the account login forms, model, etc that I was given back into my project and it fixed the problem.
Re: [RESOLVED] What are those errors/How do I fix them
Hi there. I'm having the same problem of removing from cart. But i'm having this issue on my production server. On my localhost, it is working fine.
Anyway, in your shopping cart controller line 12, shouldn't it be like below?
int itemCount = cart.RemoveFromCart(id);
I understand you have fixed your problem. Any workaround that you can suggest me to accomplish this? Was your site running on localhost or an online server when you developed this?
Re: [RESOLVED] What are those errors/How do I fix them
Hi again, sorry I missed line 20 on my previous post.
Line 12; int itemCount = cart.RemoveFromCart(id);
Line 20; ItemCount = itemCount,
Re: What are those errors/How do I fix them
Quote:
Originally Posted by
Nightwalker83
Well, I solved the above errors by rewriting the shopping cart index page. Although, now I have another problem:
Server Error in '/' Application.
The current request for action 'LogOn' on controller type 'AccountController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult LogOn(MvcMusicStore.Models.LogOnModel, System.String) on type MvcMusicStore.Controllers.AccountController
System.Web.Mvc.ActionResult Logon(MvcMusicStore.Models.LogOnModel, System.String) on type MvcMusicStore.Controllers.AccountController
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
It looks like you had two actions with the same name and parameter sets in the controller.
.
Re: What are those errors/How do I fix them
Quote:
Originally Posted by
kaneXtreme
I understand you have fixed your problem. Any workaround that you can suggest me to accomplish this? Was your site running on localhost or an online server when you developed this?
No, I have only tested the site on the local host not using an online-server.
Quote:
Originally Posted by
honeybee
It looks like you had two actions with the same name and parameter sets in the controller.
Yeah, maybe! I forget now anyway.