There has been a question at SO Why is Razor Pages the recommended approach to create a Web UI in Asp.net Core 2.0? where Steve Smith has kindly explained the benefits of using Razor Pages over full MVC from the perspective of having less files.
I've been using Razor Pages for a while and noticed that despite an advantage of a Razor Page simplicity, it is a bit complicated when it comes to custom routing, structuring folders and complex view model (page model seem to be cluttered).
So, the questions are:
I would also appreciate if some of expirienced guys shared your thoughts (pros and cons) about using Razor Pages to better understand this framework.
From the docs, "Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views." If your ASP.NET MVC app makes heavy use of views, you may want to consider migrating from actions and views to Razor Pages.
Razor Pages represents a simpler way to generate HTML on the server compared to MVC. It is recommended for all new web applications that rely on server-side HTML generation going forward. MVC is still available for existing apps. It is also probably easier to migrate older MVC 5 (.
The main difference between MVC and Razor pages is the fact that the controller code and the model are likewise included inside the Razor Page. Simply speaking, it is almost similar to an MVVM framework providing an easier development experience as well as 2-way data binding with isolated concerns.
Advantages of Razor Pages:Simple context of structure and has no controllers. Flexibility to fit any application you want to build. It has specific codes behind individual pages and is more organized. Build web apps in less time just like you did in ASP.NET Webforms.
We've recently launched a pretty decent sized app using Razor Pages for the front end and MVC controllers for the API for client side components. My experience has been this:
The pages paradigm works well when your content is structured around the idea of actual "pages" on the site. Think about things such as a Contact Us or an About or even a Login page. Sure, those could be done via MVC, but MVC is really unnecessary. A simple page will suffice. Leave the controllers to more controller'ish things like a product catalog or a user database.
If your MVC architecture revolves heavily around your view structure, razor pages is probably a good fit. You can still use the MVC bits for API related stuff, but the benefit of pages is that your front end structure becomes more explicit and less implicit ("convention-based") like with MVC where each action could or could not have a view that is typically named after the action.
Although Chris has provided a clear opinion on the frameworks being shipped with a standard ASP.NET Core Implementation. People must also note that for MS to recommend Razor Pages there's rather deeper reasons for that and they have been clear to me since I'm a big fan of razor pages.
If there is anything else except simplicity of a page to prefer Razor Pages over Controllers/Views - specifically I'm interested in performance of the two frameworks?
Is it acceptable to combine Razor Pages and Controllers/Views at the same time?
I've been using Razor Pages for a while and noticed that despite an advantage of a Razor Page simplicity, it is a bit complicated when it comes to custom routing, structuring folders and complex view model (page model seem to be cluttered).
[BindProperties]
or [BindProperty]
, you can import as many fields you want into a view... and remember that the binding is Two-Way.Unless you start working with Razor pages, you'll hear a lot of opinions about it, some will sway you away from using it, some like Chris will give you true feedback. But my advise is, Razor pages has evolved and performs best in any application of any size...
I hope you find this interesting to read.
.Net Core Family
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With