There is a form for adding products to the cart,
@using (Ajax.BeginForm("AddCart", "Cart", new AjaxOptions { UpdateTargetId = "res" })) { <div class="pull-left"> @Html.HiddenFor(x => x.Id) <input type="submit" class="btn btn-default" value="Добавить в корзину" /> </div> } AddCart method adds goods to the cart and returns a partial view that updates the counter of the quantity of goods in the cart
[HttpPost] public ActionResult AddCart(int Id) { AddProductToCart(id); return PartialView(); } Already in the basket when all the goods that are in it are withdrawn, a form is called that removes the goods from the basket:
@using (Ajax.BeginForm("RemoveFromCart", "Cart", new AjaxOptions { UpdateTargetId = "tabcart" })) { @Html.Hidden("Id", line.Product.Id) <input type="submit" class="btn btn-default" value="Удалить" /> } The RemoveFromCart method removes goods from the cart and returns a new partial view of the table with goods.
[HttpPost] public ActionResult RemoveFromCart(int Id) { RemoveProductFromCart(id); return PartialView(new CartIndexViewModel { Cart = GetCart(), ReturnUrl = null }); } But the counter with the number of goods in the header is not updated, so the question is how can I update the content of the basket with one ajax action and update the counter of the quantity of goods in the basket?