How to do it...

  1. Let's create all the code we need to display some products to add to the basket. The models will have to be serializable (models, services):
[Serializable] 
public class Product 
{ 
  public int Id { get; set; } 
  public string Name { get; set; } 
  public decimal Price { get; set; } 
} 
 
[Serializable] 
public class Basket 
{ 
  public List<Product> ListProducts { get; set; } 
  public decimal Total { get; set; } 
 
  public Basket() 
  { 
    ListProducts = new List<Product>(); 
    Total = 0; 
  } 
} public interface IProductRepository { IEnumerable<Product> GetProducts(); } public class ProductRepository : IProductRepository { private List<Product> _products; public ProductRepository() { _products = new List<Product>() { new Product { Id = 1, Name = "Laptop", ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.