PartialView not rendering

Asked by At

I'm calling a Partial View using jQuery as:

$("#cartLi")
    .click(function () {
        $.post("/ShoppingCart/cartDropDown",
            function (data) {
                $('.cart-skeleton').replaceWith(data);
                $('.cart-dropdown').css('display', 'inline-block');
            })
    });

This code successfully fires following action in the controller:

[HttpPost]
    public ActionResult cartDropDown()
    {
        var cart = ShoppingCart.GetCart(this.HttpContext);
        var viewModel = new ShoppingCartViewModel
        {
            CartItems = cart.GetCartItems(),
            CartTotal = cart.GetTotal(),
            ItemCount = cart.GetCount(),
            Message = Server.HtmlEncode("There are no items in your cart. Continue shopping.")
        };
        foreach (var item in viewModel.CartItems)
        {
            item.item = db.Items.Single(i => i.ItemID == item.ItemID);
        }
        return PartialView("_cartDetails", viewModel);
    }

This code runs successfully till the very last line (return PartialView("_cartDetails", viewModel);) and then the last closing brace - and then breaks without throwing any errors.

Not sure why this strange behavior.

0 Answers