When you want to take your website to the next level, you need to do more than display text and images. You need to handle data and route requests. That’s where page models come in!
Let’s review some points about ASP.NET Core and the page-focused Razor Pages framework:
- In view pages (.cshtml files), Razor syntax lets us mix C# and HTML code in one file so that we can make flexible templates.
- In page models (.cshtml.cs files), we use C# code and special
PageModelclasses to maintain data and handle different actions, like
This lesson will focus on page models and some of the things we can do with them, such as:
- Respond to requests using the
- Respond to requests using the asynchronous
- Use model binding to share data between view pages and page models
By the end of this lesson, you’ll understand nearly all of the code used in this page model. Run the code to see it working.
Remember that, by default, the name of the file determines its URL segment. Check that Index.cshtml matches
localhost:8000/and Archive.cshtml matches