0

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.

New contributor
Kyle Hochdoerfer is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Bring up the dev tools in the browser, select the Network tab, then click on the anchor and see what the response is. If it is a 404 then your routing has an issue. What is the URL of the page where this anchor is located?
    – Steve Py
    Commented 2 days ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.