...

/

Using Code-Behind Files with Razor Pages

Using Code-Behind Files with Razor Pages

Learn about creating a razor page illustrated through creating a suppliers list page.

Sometimes, it is better to separate the HTML markup from the data and executable code because it is more organized. Razor Pages allows us to do this by putting the C# code in code-behind class files. They have the same name as the .cshtml file but end with .cshtml.cs.

Creating a Razor Page for a list of suppliers

We will now create a Razor Page that shows a list of suppliers. In this example, we are focusing on learning about code-behind files. Next, we will load the list of suppliers from a database, but for now, we will simulate that with a hardcoded array of string values:

...