我想在我的 MVC 站点的每个页面上显示所选项目的数量。我有一个 ViewModel 定义了我想要的属性
public class CartViewModel
{
public List<CartItem> CartItems { get; set; }
public decimal CartTotal { get; set; }
}
获取 Cart 的 Controller ,将其映射到 View 模型并将其传递给
public ActionResult GetCartSummary()
{
var cart = Cart.Instance;
var viewModel = AutoMapper.Mapper.Map<Cart, CartViewModel>(cart);
return View(viewModel);
}
以及对此的看法
@model TheWorkshop.Web.Models.Edit.ShoppingCartViewModel
<h2>Cart Summary</h2>
<span>@Model.CartTotal</span>
最后在我的
_Layout.cshtml
文件@Html.Action("GetCartSummary", "Cart")
但这给了我
System.StackOverflowException was unhandled
最佳答案
尝试将以下内容添加到您的购物车 View 中:
@{Layout = null;}
关于asp.net-mvc - MVC 4 _Layout.cshtml View 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15936768/