Let's add the functionality to insert a new supplier.
Open Suppliers.cshtml.cs, and import the following namespace:
using Microsoft.AspNetCore.Mvc;
In the SuppliersModel class, add a property to store a supplier, and a method named OnPost that adds the supplier if its model is valid, as shown in the following code:
[BindProperty]public Supplier Supplier { get; set; }public IActionResult OnPost(){ if (ModelState.IsValid) { db.Suppliers.Add(Supplier); db.SaveChanges(); return RedirectToPage("/suppliers"); } return Page();}
Open Suppliers.cshtml, and add tag helpers, as shown in the following markup:
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
At the bottom of the .cshtml file, add a form to insert a new supplier, ...