0

So, i call trhough Ajax an IActionResult to go to another view and the IActionResult executes entirely except that it doesn't return the view.

Here is the code of the action result, it just take some products and search for their prices on the database and then sums them. And it executes perfectly. I changed the code a little to some lines to show me the values of each variable in the console and it works fine. The only problem is that when it suppose to show the view in the browser, nothing happens

 [HttpPost]
    public IActionResult Cart(List<int[]> carrito){
        var productsToBuy = selectProductsByID(carrito);
        var detallesOrden = new List<OrderDetailModel>();
        int sumaTotal = 0;
        for(int i = 0; i<carrito.Count; i++){           
            var detalle = new OrderDetailModel{
                idProduct = carrito[i][0],
                cantidad = carrito[i][1],
                subTotal =  productsToBuy[i].precio * carrito[i][1]
            };            
            sumaTotal += detalle.subTotal;
        }
        var orden = new OrderModel{
            estado = 0,   
            sumaTotal = sumaTotal             
        };
        ViewBag.ProductsToBuy = productsToBuy;
        ViewBag.DetallesOrden = detallesOrden;
        ViewBag.Orden = orden;
        return View();
    }

This is the function which i use to call the actionresult it sends an array with the products id and their quantities

function goToCart(){
    showCart();
    var target = '@Url.Action("Cart", "Home")';
    $.ajax({
        type: 'POST',
        data:{
            carrito: carrito
        },
        url: target,
        success: function(result){

        },
        error: function(result){
            alert('error');
        }
    });
}

What am i doing wrong? I'll appreciate any kind of help. Sorry for the combinnation of english and spanish.

0 Answers0