Answer the question
In order to leave comments, you need to log in
Two actions for one Ajax request?
There is a form for adding items 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>
}
[HttpPost]
public ActionResult AddCart(int Id)
{
AddProductToCart(id);
return PartialView();
}
@using (Ajax.BeginForm("RemoveFromCart", "Cart", new AjaxOptions { UpdateTargetId = "tabcart" }))
{
@Html.Hidden("Id", line.Product.Id)
<input type="submit" class="btn btn-default" value="Удалить" />
}
[HttpPost]
public ActionResult RemoveFromCart(int Id)
{
RemoveProductFromCart(id);
return PartialView(new CartIndexViewModel
{
Cart = GetCart(),
ReturnUrl = null
});
}
Answer the question
In order to leave comments, you need to log in
You can update the cart status on onSuccess.
Note. You don't have a uniform method naming style. AddCart - add cart(???)
RemoveFromCart - Remove from cart.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question