Sometimes, it is better to separate the HTML markup from the data and executable code, so Razor Pages allows code-behind class files.
In Visual Studio 2017, right-click on the Pages folder, select Add | New Item.... In the Add New Item dialog, select Razor Page, change the name to Suppliers.cshtml, and click on Add.
In Visual Studio Code, add two files to the Pages folder named Suppliers.cshtml and Suppliers.cshtml.cs.
Modify the contents of Suppliers.cshtml.cs, as shown in the following code, and note the following:
- SuppliersModel inherits from PageModel, so it has members such as ViewData
- SuppliersModel defines a property for storing a collection of string values
- When a HTTP GET request is made ...