I've got a shopping cart view with buttons for incrementing and decrementing the quantity of items in the cart.
The problem is that when I click the anchor tag with the asp-action
for incrementing or decrementing, the corresponding controller action is not called, instead it just links me to a blank page.
In my CartController
, I have:
public IActionResult Increment(int cartId)
{
var cartFromDb = _db.Cart.Get(u => u.Id == cartId);
cartFromDb.Count += 1;
_db.Cart.Update(cartFromDb);
_db.Save();
return RedirectToAction(nameof(Index));
}
And in my Index
view for Cart
:
<a asp-area="Customer" asp-controller="Cart" asp-action="Increment"
asp-route-cartId="@item.Id" class="btn btn-primary">
<i class="bi bi-plus-lg"></i>
</a>
The URL for the blank page it sends me to is
https://localhost:7245/Customer/Cart/Increment?cartId=3
Note that 3 is the correct Id
for the item I tried to increment. It seems to be ignoring the Increment
action altogether, I tried setting breakpoints and they weren't being hit.