I want to display a count of selected items on every page in my MVC site. I have a ViewModel that defines the properties I want there
public class CartViewModel
{
public List<CartItem> CartItems { get; set; }
public decimal CartTotal { get; set; }
}
a controller that gets the Cart, maps it to the view model and passes that on
public ActionResult GetCartSummary()
{
var cart = Cart.Instance;
var viewModel = AutoMapper.Mapper.Map<Cart, CartViewModel>(cart);
return View(viewModel);
}
and a view for that
@model TheWorkshop.Web.Models.Edit.ShoppingCartViewModel
<h2>Cart Summary</h2>
<span>@Model.CartTotal</span>
and finally in my _Layout.cshtml file
@Html.Action("GetCartSummary", "Cart")
But this gives me
System.StackOverflowException was unhandled