I have been working from the music store tutorial and completed it. However at the end the "remove from basket" link doesnt work. A member on here sent me the MVC 4 beta and I have looked at that but still cannot get it to work.
I can't see what needs to be changed/removed/added so any help would be greatly appreciated!
If memory serves me, this is an "ajax" portion of the tutorial. Essentially, the "remove from basket" actionlink will have two parts. The first part is the action name, which calls the controller's action to perform an item's removal (there's probably
an id attribute tied to the action). The second part of the actionlink is the result handler. This tells your View what to do once the controller action has returned it's content.
Since the link "doesn't work", I'll assume you mean it's not removing the item from the basket. Look at the actionlink and find the action name. Then go to your controller and look for where that action name is. Within that action is where you'll want
to look for why it's not working.
You should run a debug with breakpoints in that action to see where things go wrong.
I've looked through it and cant see anything wrong. I've read elsewhere that it's got something to do with the ajax or JS coding. I'm new to this mate so my understanding is very limited atm!
Stick a breakpoint on your action and debug. When you click the "remove" link, does it jump to your action's break point? If no, then there's a communication issue with your script. If it does jump to the break point, stick another breakpoint at "int
itemCount = ..." and tell me if "MovieName" has any values.
Also, I just want to say that if you follow the tutorials without modifying the models, they should work without errors. The changes you've made to the original models might not work with the code from the tutorial. My advice is to go through any tutorial
with the given models until you have an understanding of what's going on. Then after you finish the tutorial, create your own models and use the tutorial as a reference... not a template. I don't mean to discourage what you're doing, but I feel you are creating
more problems because you've modified critical portions of the tutorial. You're taking code that was intended for specific models and are trying to make that same code fit toward your custom models.
edit: the green lines from your actionlink html shows up because the editor doesn't recognize those parameters. However, the browser should understand what they mean. I don't think this is an issue that affects your link not working.
When I click on remove from cart it does nothing. Just stays on the same page. Been at it for a while now looking everywhere but cannot figure out what the problem is with this as well as the other problem!
The tutorial is known to have a few bugs in and I followed it exactly and was working fine apart from this bit. Been searching online and others are having the same problem and they followed it exactly using everything they were given. A member on here sent
me an updated tutorial but I still could not get it to work.
uzzy
0 Points
116 Posts
Music Store "Remove from basket"
Apr 10, 2012 06:56 PM|LINK
Hi
I have been working from the music store tutorial and completed it. However at the end the "remove from basket" link doesnt work. A member on here sent me the MVC 4 beta and I have looked at that but still cannot get it to work.
I can't see what needs to be changed/removed/added so any help would be greatly appreciated!
Thanks
JohnLocke
Contributor
3738 Points
807 Posts
Re: Music Store "Remove from basket"
Apr 10, 2012 08:26 PM|LINK
If memory serves me, this is an "ajax" portion of the tutorial. Essentially, the "remove from basket" actionlink will have two parts. The first part is the action name, which calls the controller's action to perform an item's removal (there's probably an id attribute tied to the action). The second part of the actionlink is the result handler. This tells your View what to do once the controller action has returned it's content.
Since the link "doesn't work", I'll assume you mean it's not removing the item from the basket. Look at the actionlink and find the action name. Then go to your controller and look for where that action name is. Within that action is where you'll want to look for why it's not working.
You should run a debug with breakpoints in that action to see where things go wrong.
uzzy
0 Points
116 Posts
Re: Music Store "Remove from basket"
Apr 11, 2012 12:53 PM|LINK
I've looked through it and cant see anything wrong. I've read elsewhere that it's got something to do with the ajax or JS coding. I'm new to this mate so my understanding is very limited atm!
Thanks
JohnLocke
Contributor
3738 Points
807 Posts
Re: Music Store "Remove from basket"
Apr 11, 2012 01:09 PM|LINK
Post the "remove from basket" actionlink. Also, post the action code associated with the actionlink.
uzzy
0 Points
116 Posts
Re: Music Store "Remove from basket"
Apr 11, 2012 01:15 PM|LINK
public ActionResult RemoveFromCart(int id)
{
// Remove the item from the cart
var cart = ShoppingCart.GetCart(this.HttpContext);
// Get the name of the movie to display confirmation
string MovieName = storeDB.Carts.Single(item => item.RecordId == id).Movie.Title;
// Remove from cart
int itemCount = cart.RemoveFromCart(id);
// Display the confirmation message
var results = new ShoppingCartRemoveViewModel
{Message = Server.HtmlEncode(MovieName) + " has been removed from your shopping cart.", CartTotal = cart.GetTotal(),
CartCount = cart.GetCount(),
ItemCount = itemCount,
DeleteId = id};
return Json(results);}
View Code:
<a href="#" class="RemoveLink" data-id="@item.RecordId"
data-url='@Url.Content("~/ShoppingCart/RemoveFromCart")'>Remove from cart</a>
A green line appears under the two parts underlined and in bold
JohnLocke
Contributor
3738 Points
807 Posts
Re: Music Store "Remove from basket"
Apr 11, 2012 01:49 PM|LINK
Stick a breakpoint on your action and debug. When you click the "remove" link, does it jump to your action's break point? If no, then there's a communication issue with your script. If it does jump to the break point, stick another breakpoint at "int itemCount = ..." and tell me if "MovieName" has any values.
Also, I just want to say that if you follow the tutorials without modifying the models, they should work without errors. The changes you've made to the original models might not work with the code from the tutorial. My advice is to go through any tutorial with the given models until you have an understanding of what's going on. Then after you finish the tutorial, create your own models and use the tutorial as a reference... not a template. I don't mean to discourage what you're doing, but I feel you are creating more problems because you've modified critical portions of the tutorial. You're taking code that was intended for specific models and are trying to make that same code fit toward your custom models.
edit: the green lines from your actionlink html shows up because the editor doesn't recognize those parameters. However, the browser should understand what they mean. I don't think this is an issue that affects your link not working.
uzzy
0 Points
116 Posts
Re: Music Store "Remove from basket"
Apr 11, 2012 03:22 PM|LINK
When I click on remove from cart it does nothing. Just stays on the same page. Been at it for a while now looking everywhere but cannot figure out what the problem is with this as well as the other problem!
The tutorial is known to have a few bugs in and I followed it exactly and was working fine apart from this bit. Been searching online and others are having the same problem and they followed it exactly using everything they were given. A member on here sent me an updated tutorial but I still could not get it to work.
Again, thanks for your help mate