我想在我的MVC站点的每个页面上显示所选项目的计数.我有一个viewmodel,它定义了我想要的属性
public class Cartviewmodel { public List<CartItem> CartItems { get; set; } public decimal CartTotal { get; set; } }
获取Cart的控制器,将其映射到视图模型并传递它
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
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。