Q&A: Developing Web Sites with ASP.NET Core Razor Pages
Microsoft says Razor Pages development in ASP.NET Core can make coding page-focused web-dev scenarios easier and more productive than using the controllers and views integral to another option: the Model View Controller (MVC) approach.
Specifically, company documentation states: "Razor Pages is a page-based model. UI and business logic concerns are kept separate, but within the page. Razor Pages is the recommended way to create new page-based or form-based apps for developers new to ASP.NET Core. Razor Pages provides an easier starting point than ASP.NET Core MVC."
To help .NET-centric developers get started building web projects with this approach, Microsoft MVP Philip Japikse is conducting an intermediate-level, full-stack development session during the big Live!360 tech conference being held in Orlando Nov. 13-18.
Attendees of the Nov. 15 presentation titled Websites with ASP.NET Core Razor Pages will dig into the details of View Components, Tag Helpers, Routing and much more in the session that runs from 9:15 a.m. to 10:30 a.m.
We caught up with the well-known international speaker to get more details on the session in a short Q&A.
VisualStudioMagazine: Can You Briefly Explain the Foundation of ASP.NET Core?
Japikse: ASP.NET Core is the next evolution for web development using the Microsoft stack. Based on .NET (Core), ASP.NET Core is a complete re-architecture and rewrite of the very popular ASP.NET framework. ASP.NET Core not only focuses on developer productivity, but also performance. With each release of ASP.NET Core, the benchmarks place the framework as one of the fastest available. With ASP.NET Core, you can develop RESTful services, web applications (using Razor Pages or the Model View Controller (MVC) pattern) and Single-Page Applications (SPA) using Blazor.
What Are Your Favorite New Features in ASP.NET Core Razor Pages?
For me, the reason I like Razor Pages is twofold. The first is the familiar Razor view engine. If you have worked in MVC applications before, many of the capabilities will be very natural to you: layout pages, templates (display and editor) and the advantage of being able to stay in the markup with Razor. The second is the speed to develop web applications.
"Since Razor Page-based applications are page focused and don't use the MVC pattern, each page can stand on its own. It creates a lower barrier to entry than its MVC counterpart, and I find it works great for smaller applications."
Philip Japikse, Microsoft MVP, ASPInsider, MCSD, PSM II, PSD and PST
Since Razor Page-based applications are page focused and don't use the MVC pattern, each page can stand on its own. The
Post methods plus routing parameters are in the code-behind file for the view. It creates a lower barrier to entry than its MVC counterpart, and I find it works great for smaller applications.
What New Features Would You Like to See in ASP.NET Core Razor Pages?
The one part of Razor Page-based web applications that blocks us from using them at scale in large applications is the friction required to achieve code reuse through inheritance. While you can technically create a base page and inherit from that in your Razor pages, there isn't the level of support and reuse that you get when developing an enterprise application using the MVC pattern.
What Pain Points Do Developers Typically Encounter in Getting Started with ASP.NET Core Razor Pages?
If you have used ASP.NET MVC in the past, the Razor view engine will be very comfortable to you. I think the biggest difficulty will be getting back into a page-based routing system and getting used to code-behind files again. Code-behind files have a rather nasty legacy, and MVC developers will need to move past the history and embrace the new. A lot of care went into Razor pages to prevent the mistakes of the code-behind files in ASP.NET Web Forms.
If you are coming from a Web Forms background, the Razor view engine is quite different than the Web Forms view engine. While infinitely improved, it will take some getting used to. While there are some familiar patterns (like base layout pages and a page-based routing engine), moving from Web Forms to ASP.NET Core is probably a bigger leap than moving from ASP.NET MVC to Razor Page-based applications.
As Blazor Has Made a Big Splash by Allowing C# Web Development, what's the Role of ASP.NET Core Razor Pages Amid All the Blazor Hype?
If you were to follow up your question with "which one is better," I would answer both Blazor and Razor Pages are very solid, even as new as Blazor WebAssembly is. The best part of the discussion is that now, as a Microsoft stack-based developer, you have many different choices of how to build your applications.
About the Author
David Ramel is an editor and writer for Converge360.