In this recipe, you will learn what a model binder is, and how to use it.
We will create an ASP.NET Core MVC Web Application template by going to File
| New
| Project
| AspNet Core Web Application
.
- First, let's add the
AutoMapper
dependency toproject.json
. - After that, we will create the
ProductRepository
with fake data. OurHomeController
controller class will consume the data from this repository. The objects consumed from the repository will beProductDto
objects, but we will use them only to transport data between the repository and the controller:
public class ProductDataStore { public static ProductDataStore Current { get; } = new ProductDataStore(); public List<ProductDto> Products { get; set; } public ProductDataStore() { Products = new List<ProductDto>() { new ProductDto { Id = 1, Name = "Laptop" }, new ProductDto { Id = 2, Name = "Phone" }, new ProductDto { Id = 3, Name = "Desktop...