您好,我正在尝试制作一个简单的在线杂志,并且当用户点击addtoCart按钮时,我得到了这个部分
我的模型购物车拥有两个属性 - 产品和数量
public class Cart
{
public ProductLanguages Product { get; set; }
public int Quantity { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
所以在我的AddProductToCart方法中的basketViewModel(类)中,我添加了产品,我从List的属性中获取了数据库的详细信息.
所以我无法弄清楚这个问题:控件中的某个地方我应该在Session中保存这个列表,如果用户下次我应该从这个会话中获取更多的产品.如果有人能给我一个带有索引动作的控制器的例子,我会非常感激.
public class BasketViewModel
{
private readonly IProductLanguagesRepository prodlanRepository;
public List<Cart> listProductsinBasket { get; set; }
public BasketViewModel() : this(new ProductLanguagesRepository())
{
}
public BasketViewModel(IProductLanguagesRepository prodlanRepository)
{
this.prodlanRepository = prodlanRepository;
}
public void AddProductToCart(int id,int quantity)
{
ProductLanguages nwProduct = prodlanRepository.GetProductDetails(id);
if (nwProduct != null)
{
Cart cr = new Cart();
cr.Product = nwProduct;
cr.Quantity = …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×1