Join Jess Chadwick for an in-depth discussion in this video What is Razor Pages?, part of ASP.NET Core: Razor Pages.
- [Instructor] Razor Pages is a first-class web development framework that sits on top of the lightweight cross-platform and super fast ASP.NET Core runtime. Not only that, Microsoft is now recommending Razor Pages as the preferred way to build applications on the ASP.NET Core runtime. The Razor Pages framework leverages the powerful and mature Razor view syntax that's been popular since its introduction to ASP.NET MVC in 2013.
And if offers a simplified page-based development model that appeals to a wide audience that might not have been happy that the only option that ASP.NET Core offered previously had been the Model-View-Controller pattern. When I use the term page-based development model, I'm referring to the fact that there's a direct link between the URL of a page and its physical location on the server. For instance, when a user navigates to the URL mysite.com/account/profile, Razor Pages would look on the server for the folder named Account and the file named Profile.cshtml within that folder and then render it.
If you've ever used frameworks such as JSP, ASP.NET Web Forms, or PHP, you're already familiar with this approach since it's exactly the same way those frameworks operate as well. What makes Razor Pages different than these other frameworks is that it is built with maintainability in mind. For example, in addition to offering features such as dependency injection right in the view, the framework also encourages you to create a class outside of the page to store your application logic, keeping it separate from your markup.
This allows you to achieve a pretty strong separation of concerns, like the very popular Model-View-Controller approach that the ASP.NET Core MVC framework provides, only with far less boilerplate code. In fact, underneath it all, Razor Pages actually is ASP.NET Core MVC. That is to say, Razor Pages offers quite a different development model and even its own new APIs. However, it's actually an abstraction on top of the ASP.NET Core MVC framework.
That means that you still have access to all of the great features and APIs that ASP.NET Core MVC offers, but with a simpler and more straightforward development model. And what's more, because Razor Pages is built on top of ASP.NET Core MVC, they actually work really well together in the same application. So, feel free to combine MVC-based controllers with your Razor Pages, or even begin adding some Razor Pages to your existing ASP.NET Core MVC applications.
- Creating a new application
- Setting up pages
- Rendering dynamic content
- Reusing markup with layouts
- Increasing the maintainability of pages
- Processing data
- Validating input
- Securing an application