In this recipe, we will learn how to use/create a hybrid ViewComponent
/controller
class.
We will create an empty web application with ASP.NET Core MVC enabled, adding the MVC dependency to the project:
"Microsoft.AspNetCore.Mvc": "2.0.0"
In this recipe, we will create a basket component and place it in the _Layout.cstml
file.
This way, the basket component will be visible for every page. The basket object will be stored in Session.
- 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>();...