There is a bug in the RemoveFromCart method

Oct 25, 2010 at 12:52 PM
Edited Oct 25, 2010 at 12:53 PM

This bug is present in all version of MvcMusicStore.

the code of RemoveFromCart in ShoppingCart Model is:

 public void RemoveFromCart(int id)
//Get the cart
var cartItem = storeDB.Carts.Single(
cart => cart.CartId == shoppingCartId
 && cart.RecordId == id);
if (cartItem != null)
if (cartItem.Count > 1)

This mean you are removing record one by one. For example, if you have 3 items in 1 record, and you make a "Remove from cart" action, this will keep 2 item in your cart

But the Javascript code in ShoppingCart View is:

<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 + ')');


This will delete an entire row. If you make a F5 press, you will see that remain 2 items in that record.

The correct Javascript code is:

var json = context.get_data();
var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
var count = data.Count;
if (count == 0) {
$('#row-' + data.DeletedId).fadeOut('slow');
} else {
 with count is the quantity of albums in this record.

Oct 25, 2010 at 11:12 PM

Thanks, great catch! Originally we didn't track quantity with orders, and it looks like I didn't update the Javascript with that change. Will get this in the next release.

Oct 25, 2010 at 11:31 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.