The shopping card in mvcmusicstore uses the session variable. That should be unique for each user.
The delete link is most likely caused by a path reference problem. I'm guessing you're deploying to a virtual directory (sub folder) in IIS. That often causes problems with hardcoded paths. MVC music store uses a jquery ajax post to delete the user. You
need to make sure you user @Url.Action instead of hardcoding in a path to the delete action method. In the shopping card index view. Make the following change:
//Change this line
$.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
//To this
$.post("@Url.Action("RemoveFromCart","ShoppingCart")", { "id": recordToDelete },
Basically instead of hardcoding in the url, we are letting the mvc framework resolve the url. If the application is local or an the site root, the framework will generate a url of /ShoppingCard/RemoveFromCart. But if the mvc applicationg is deployed a virtual
directory, it will now appear in the correct path.
postonoh
Member
498 Points
259 Posts
Having problem with my shopping mvc?
Apr 18, 2012 09:43 PM|LINK
I started using the shopping code form music mvc everything was going good then I notice two things.
one is: When I purchase an item show listed in cart. I logout as user close browser open browser login as a different user item cart is still present.
using IIS 7.5.
Second is: When using VS2010 I can delete items using the music cart but when using IIS will not delete.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Having problem with my shopping mvc?
Apr 18, 2012 10:15 PM|LINK
The shopping card in mvcmusicstore uses the session variable. That should be unique for each user.
The delete link is most likely caused by a path reference problem. I'm guessing you're deploying to a virtual directory (sub folder) in IIS. That often causes problems with hardcoded paths. MVC music store uses a jquery ajax post to delete the user. You need to make sure you user @Url.Action instead of hardcoding in a path to the delete action method. In the shopping card index view. Make the following change:
//Change this line $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete }, //To this $.post("@Url.Action("RemoveFromCart","ShoppingCart")", { "id": recordToDelete },Basically instead of hardcoding in the url, we are letting the mvc framework resolve the url. If the application is local or an the site root, the framework will generate a url of /ShoppingCard/RemoveFromCart. But if the mvc applicationg is deployed a virtual directory, it will now appear in the correct path.
Blog | Twitter : @Hattan
postonoh
Member
498 Points
259 Posts
Re: Having problem with my shopping mvc?
Apr 18, 2012 10:26 PM|LINK
Thanks, I should have read the documentation.
postonoh
Member
498 Points
259 Posts
Re: Having problem with my shopping mvc?
Apr 19, 2012 02:00 PM|LINK
Thanks I use the code did not work. But looking up what you gave allowed me look at the complete ajax post and the problem was the
<script src="~/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
I had to change it to this <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
Not it is firing thanks.