Hi @Luis Maldonado,
Is there a reason to avoid mixing MVC and Razor Pages in a project?
Is it a good/bad practice?
From a pro perspective, how does mixing MVC and Razor approaches look?
As we all known, a Razor Page has similarities with the view component of ASP.NET MVC. Just like MVC, it has almost the same functionality as well as syntax. 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.
Razor Pages work well when your content is structured and is ideal for the login page or contact us page due to its simplicity. MVC is for complex databases of users or product descriptive lists. Heavy apps constructed using MVC can get cluttered by too many programmers handling codes as some may miss out on good programming practices.
Razor Pages requires you to put code related to the specific page. To enable better control split codes, it saves you from managing huge coding in the controller. Optionally you can create external classes for the logic to keep the controllers clean.
By using the ASP.NET Core Identity, it includes a default UI as a Razor library that enables you to quickly add users to an application, without having to build all the UI yourself. If you want to add customer user data to identity, it is easier to achieve.
If you don't want to use the Scaffold Identity and prevent use Razor page in your application, you can remove the following code in the Startup.cs file:
services.AddRazorPages();
and endpoints.MapRazorPages();
And you have to create all the relates page to manage user, roles and more.
In my opinion, I might choose to use the mixing MVC and Razor approaches, because Scaffold Identity can generate these pages, and all the Identity relates page was in the Identity/Pages folder, it is easier to find them and the relates model.
Finally, whether using the one-pattern or mix-pattern, it should depend on your application and choice.
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion