ASP.NET Core Razor pages vs Full MVC Core

asp.net-core-mvcrazor-pages

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:

  1. 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?
  2. Is it acceptable to combine Razor Pages and Controllers/Views at the same time?

I would also appreciate if some of expirienced guys shared your thoughts (pros and cons) about using Razor Pages to better understand this framework.

Best Answer

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.