Edit: the product view contains some products so I'm trying to add them one by one to the cart using a button for each product, the added products shall appear in a table in the partial view (cart) which is working fine, I'm trying now to render this cart inside a popup modal so when i press the popup button it should show me what products i added,when i still inside the product view.
I'm trying to do something like this inside the modal body:
@Html.Partial("_ShowCart", new List<InternetApp.Models.Cart>())
but this retrieves an empty list.
So I want something like this but I don't know how I could do this with different models:
@Html.Partial("_ShowCart", Model)
I have 3 models: product, cart and viewmodel:
public class Product
{
public int id { get; set; }
public String name { get; set; }
public float price { get; set; }
public String image { get; set; }
public String description { get; set; }
public int? CategoryId { get; set; }
}
public class Cart
{
public int product_id { get; set; }
public DateTime added_at { get; set; }
public virtual Product product { get; set; }
}
public class ProductCart
{
public Product Product { get; set; }
public Cart Cart { get; set; }
}
The cart and the product each one has controller, I have the cart as a partial view which takes IEnumerable<Cart>
and a product view which takes IEnumerable<Product>
.
This is the cart index action
public ActionResult Index()
{
List<Cart> Cart = db.Cart.Include(a => a.product).ToList();
return PartialView("_ShowCart", Cart);
}
I don't know how to render the cart inside the product because each one has a different IEnumerable
model...