What are the differences between ASP.NET MVC and ASP.NET Razor Pages?

Asked

Viewed 3,207 times

6

What are the differences and limitations between ASP.NET MVC and ASP.NET Razor Pages?

I was very curious, because apparently the Razor Pages use the MVC standard, but without the need to use a controller, I don’t even know if it’s really this, and if it is, it probably shouldn’t just be this.

It also has some advantage in using one or the other?

There is some indication that ASP.NET Razor Pages can grow and become popular as ASP.NET MVC?

2 answers

7


The first thing you need to understand is that Razor Pages is like MVC, it’s not a new technology, it totally depends on MVC. It is a simpler way to use the MVC by joining the VC in a single unit, because most of the time it is enough.

To tell the truth I see little sense in the use of MVC in the way they use.

You can use the MVC full where you need it and Razor Pages where you can. It’s not a binary choice. Mix if you need it.

What really changes is the organization of the code. You can still have a file with the code and a file with the HTML, but it’s all part of the view, it’s like a code Behind that you have in ASP.NET Webforms, you decide how to organize. There are methods to handle all requests by default, no need to keep creating a method for each request.

Overall I think that’s it.

Why is there the MVC?

To modularize, give independence to each part of the application, handle complex routes. Then you can have several different views, several different models and several different controllers interacting in various ways.

The way they make the application the model never changes, and the view even less, nor has much to change, except in the case of the Webapi that the vision ceases to exist. Why complicate something when it’s always the same?

What’s the point of creating 3 layers if every change you make has to touch the 3? What’s the point of this design pattern if it creates complication? It serves precisely to make interchangeable for responsibility. If the application does not need this much of the selling argument is lost.

But today it became easy to sell something, just talk a lot about it and people think that it solves everything.

Upside

Every time you stop using something you don’t need, you have the advantage. People use a lot without thinking why they’re using that, they’re just following the recipe they’ve learned.

Do you know why your mother will make the recipe she learned on television and it doesn’t look good? Because she followed the recipe. But she doesn’t know how to do it. There are always factors that aren’t the same every time you do that. The environment is different, the brand of the product is different, the fire force is different, the time it took to reach a point changes. You have to know what to do, you can’t just follow the recipe.

Of course the tool has to help, and now we have something that goes the simplest way.

There are people who say they have other advantages, but in general it is snake oil for most cases, ie only cure a disease non-existent, is placebo.

Adoption

Adoption is difficult to predict, I would say because it is better for the vast majority of cases and because there is incentive to use it (it is the standard application in Visual Studio for ASP.NET Core). I think they even fixed some mistakes.

ASP.NET Core Razor Pages

Too bad I didn’t find Scott Hanselman’s article saying it should be the default choice and only adopt MVC when Razor Pages doesn’t answer.

Since we are in the field of opinion, I’ve always found the controller A little exaggerated for most cases. If the model is done right, it’s smart, and the presentation knows what to do with the data a little bit harder, that’s all it needs. Of course loses the ability to exchange parts.

Completion

It’s like PHP was in the past (which you can still use), a simple way to generate a page on backend. It’s a shame that it got lost, because for most cases it’s enough. MVC is only needed when you have something complex, very flexible routes.

See more

2

Razor Pages features unified View and Controller layers, similar to a code Behind.

In a small application where there will not be so much cross-information, it is worth using Razor Pages. Even your Viewmodel can compose the back end of the Razor page.

Now, it is important to evaluate one thing well: Can this small application grow? If the answer is yes, consider using the MVC, after all, as already explained in previous response, increases its modularization power.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.