MVC 4 _Layout.cshtml viewmodel

asp.net-mvc, razor

Solution

Try adding the following to your cart view:

@{Layout = null;}

Problem

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

Original source