-
Notifications
You must be signed in to change notification settings - Fork 25.1k
[WIP] RP vs MVC #7801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] RP vs MVC #7801
Conversation
@scottsauber @sporty81 please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of great information here! I have some suggestions for reorganizing and supplementing it.
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
By [Scott Sauber](https://twitter.com/scottsauber) and [Rick Anderson](https://twitter.com/RickAndMSFT) | ||
|
||
Razor Pages is a feature of the ASP.NET Core MVC framework. Razor Pages follows the MVVM pattern. Developers and teams familiar with ASP.NET MVC development: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you link to an overview of MVVM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is an abrupt transition from starting to introduce RP to saying you can still use MVC. If this is aimed at MVC developers, I would save this theme for last and jump into the comparison here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's aimed at everyone with special attention to MVC developers. I need to assure them right off the bat that MVC/controllers/views is not going away and that we're continuously investing in it. Read #6146 to see what we're trying to address.
* Can continue app development featuring controllers and views. | ||
* Can be assured the ASP.NET Core framework will provide improvements to controller/view development. | ||
|
||
Razor Pages can be added to controller/view projects. The controller-view approach to MVC may be preferred by larger teams. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto - I would save this for the end.
|
||
Razor Pages can be added to controller/view projects. The controller-view approach to MVC may be preferred by larger teams. | ||
|
||
If you haven't tried Razor Pages, consider using them. Many developers find Razor Pages development simpler and more productive than using controllers and views. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto again, save for the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Customers may find MVC more productive if they're heavily invested in it. Consider an ASP.NET 4.x app that was ported to ASP.NET Core 1.x. The team's devs can follow a pattern that's long been established when creating a new page in the app. My opinion is that it makes ASP.NET Core more approachable to beginners, since there are fewer moving parts. It's easier to ramp up on the tech because of this.
|
||
If you haven't tried Razor Pages, consider using them. Many developers find Razor Pages development simpler and more productive than using controllers and views. | ||
|
||
Razor Pages advantages over controller/view development: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IF we're going to present differences as advantages for RP, we should be sure to include differences that are advantages for MVC as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought on this comment occurs to me -- if we think MVC has no advantages, and if this article is really not so much about comparing the two as it is about "why RP is better than controllers/views and why you should try it", I would consider incorporating this content into the RP intro instead of this separate doc.
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
Razor Pages advantages over controller/view development: | ||
|
||
* **A better folder structure by default that scales better.** In MVC, the default folder structure does not scale. Separate folders for Views, Controllers, and often ViewModels when all three are tightly coupled to one another. You must bounce between all three folders anytime you need to add or change a feature. With Razor Pages, your `PageModel` (Controller + ViewModel) are in the same folder as your View. You hit F7 in Visual Studio to toggle between them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PageModel are --> PageModel is
does not scale --> is not easy to work with
(what you're describing isn't so much scaling as a structure that is intrinsically awkward to work with)
* All the Employee pages are under the */Employee* folder. | ||
* The app can authorize an entire folder and require the user must be an Administrator to get to any subfolder of */Administrator*. The code to do this is more straightforward that than with multiple Controllers that make up the Administrator features. | ||
* **More secure by default.** Razor Pages provides: | ||
* [AntiForgeryToken validation](xref:razor-pages/index#xsrfcsrf-and-razor-pages) by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't MVC have a similar default?
aspnetcore/razor-pages/rp-mvc.md
Outdated
* The app can authorize an entire folder and require the user must be an Administrator to get to any subfolder of */Administrator*. The code to do this is more straightforward that than with multiple Controllers that make up the Administrator features. | ||
* **More secure by default.** Razor Pages provides: | ||
* [AntiForgeryToken validation](xref:razor-pages/index#xsrfcsrf-and-razor-pages) by default. | ||
* You opt-in to the properties that need to be model bound via `[BindProperty]`. `[BindProperty]` prevents over-posting attacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MVC has the same feature, doesn't it?
* **More secure by default.** Razor Pages provides: | ||
* [AntiForgeryToken validation](xref:razor-pages/index#xsrfcsrf-and-razor-pages) by default. | ||
* You opt-in to the properties that need to be model bound via `[BindProperty]`. `[BindProperty]` prevents over-posting attacks. | ||
* The `PageModel` acts like a view model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some explanation of how this is more secure vis-a-vis controllers/views would be helpful.
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
## Razor Pages compared to Web Forms | ||
|
||
Razor Pages and Web Forms are page focused and each contain a *.cs* file associated with the markup page. Other than the page focus, Razor Pages are very different from Web Forms. It can be difficult to migrate Web Forms code to Razor Pages. Converting between Razor Pages and ASP.NET Core MVC is generally straightforward. Razor Pages and Web Forms have very little in common. Razor Pages and ASP.NET Core MVC share most of the ASP.NET Core framework. The following section shows many features shared between Razor Pages and ASP.NET Core MVC that are not found in Web Forms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
each contain --> each contains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be made clear that Web Forms isn't supported in ASP.NET Core. This paragraph could lead a reader to believe it is supported. Maybe just prefix "Web Forms" with "ASP.NET 4.x"?
aspnetcore/razor-pages/rp-mvc.md
Outdated
|areas| x | 2.1 | | ||
|Partial views| x | na | | ||
|View Components | x | x| | ||
|Build in DI | x | x | No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abrupt ending here, some kind of next steps link(s) would be helpful.
I'd like to see a section on controller/views advantages. From this table I'd guess that partial views is a significant advantage.
aspnetcore/razor-pages/rp-mvc.md
Outdated
description: Contrast and compare Razor Pages to controller/view programming in ASP.NET Core | ||
monikerRange: '>= aspnetcore-2.0' | ||
ms.author: riande | ||
ms.date: 8/05/2018 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the metadata reference, the mm/dd/yyyy format should be used (08/05/2018).
|
||
Razor Pages can be added to controller/view projects. The controller-view approach to MVC may be preferred by larger teams. | ||
|
||
If you haven't tried Razor Pages, consider using them. Many developers find Razor Pages development simpler and more productive than using controllers and views. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Customers may find MVC more productive if they're heavily invested in it. Consider an ASP.NET 4.x app that was ported to ASP.NET Core 1.x. The team's devs can follow a pattern that's long been established when creating a new page in the app. My opinion is that it makes ASP.NET Core more approachable to beginners, since there are fewer moving parts. It's easier to ramp up on the tech because of this.
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
## Razor Pages compared to Web Forms | ||
|
||
Razor Pages and Web Forms are page focused and each contain a *.cs* file associated with the markup page. Other than the page focus, Razor Pages are very different from Web Forms. It can be difficult to migrate Web Forms code to Razor Pages. Converting between Razor Pages and ASP.NET Core MVC is generally straightforward. Razor Pages and Web Forms have very little in common. Razor Pages and ASP.NET Core MVC share most of the ASP.NET Core framework. The following section shows many features shared between Razor Pages and ASP.NET Core MVC that are not found in Web Forms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be made clear that Web Forms isn't supported in ASP.NET Core. This paragraph could lead a reader to believe it is supported. Maybe just prefix "Web Forms" with "ASP.NET 4.x"?
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
Razor Pages advantages over controller/view development: | ||
|
||
* **A better folder structure by default that scales better.** In MVC, the default folder structure does not scale. Separate folders for Views, Controllers, and often ViewModels when all three are tightly coupled to one another. You must bounce between all three folders anytime you need to add or change a feature. With Razor Pages, your `PageModel` (Controller + ViewModel) are in the same folder as your View. You hit F7 in Visual Studio to toggle between them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change "better" to "simpler". The word "better" seems too subjective.
@scottsauber would like your comments and review. |
Definitely! I appreciate the opportunity to review this. I’ll review it tonight after work if that’s ok? |
Really sorry... I'll look tonight. Got caught up with other things last night. Edit: My plan was to just pull this branch down and run DocFX to view it... is that the best way since I don't have access to that URL? |
@scottsauber no hurry-next week fine |
@scottsauber DocFX is the best way to preview your changes locally. With DocFX installed, you can run |
aspnetcore/razor-pages/rp-mvc.md
Outdated
|[Partial views](xref:mvc/views/partial)| x | x | | ||
| Filters | [MVC](xref:mvc/controllers/filters) | [RP](razor-pages/filter) | | ||
|View Components | x | x| | ||
|[Built in DI](xref:fundamentals/dependency-injection) | x | x | No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to think of some other ones to add here.
Some ideas if you think any of these are worth adding:
- Validation/ModelState
- Routing (although it is different in both)
- Layouts
- _ViewStart.cshtml and _ViewImports.cshtml
- Tag Helpers
Ultimately... Razor Pages is just some sugar on top of MVC if that's part of the intent to drive home with this table.
aspnetcore/razor-pages/rp-mvc.md
Outdated
* The app can authorize an entire folder and require the user to be an Administrator to get to any subfolder of */Administrator*. The code to do this is more straightforward than using multiple Controllers for Administrator features. | ||
* **More secure by default.** Razor Pages provides: | ||
* [AntiForgeryToken validation](xref:razor-pages/index#xsrfcsrf-and-razor-pages) by default. | ||
* You opt-in to the properties that need to be model bound via `[BindProperty]`. `[BindProperty]` prevents over-posting attacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe provide a link to over posting attacks in case someone reading has no clue what this is. OWASP uses the term Mass Assignment although their example is in Spring + Java. Maybe we should use over-posting/mass assignment since those terms are used interchangeably.
Not sure if you want to link to external blogs or not but Hanselman has a good example here that's MVC specific: https://www.hanselman.com/blog/ASPNETOverpostingMassAssignmentModelBindingSecurity.aspx and Scott Allen has a good one too: https://odetocode.com/Blogs/scott/archive/2012/03/11/complete-guide-to-mass-assignment-in-asp-net-mvc.aspx
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
By [Scott Sauber](https://twitter.com/scottsauber) and [Rick Anderson](https://twitter.com/RickAndMSFT) | ||
|
||
Razor Pages is a feature of the ASP.NET Core MVC framework. Razor Pages follows the [MVVM](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/mvvm) pattern. Developers and teams familiar with ASP.NET MVC development: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me this kinda reads a little funny that it says it's a feature of the MVC framework, then immediately says it follows MVVM which someone might be like "what? how can it be a feature of MVC if it follows a (slightly) different pattern in MVVM?" Just kinda the unfortunate naming of MVC than anything else though Not sure I have any better wording here or specific suggestions, other than maybe moving that MVVM line to another part?
I think it should definitely be mentioned somewhere on this doc that the guidance for Razor Pages is to be used with server-rendered HTML scenarios and use MVC if you're strictly building API's for say a front-end like React, Angular, Vue, etc. Someone who's building just API's should not use Razor Pages. Part of the reasoning that could be mentioned is if you use Razor Pages for API's, you essentially have a useless .cshtml file laying around, because there's no View being served up. You can send/receive JSON from Razor Pages, but if you do that, that API endpoint should probably be tightly associated with a page (like say a cascade dropdown scenario). Otherwise, a more generic API/RESTful API makes more sense to be in a Controller. I think this is backed up by the guidance provided in the templates where the API template uses MVC. Along the same lines, the Web Application template with Razor Pages uses Controllers for things where there's no UI/Page to show (like Log Out). Maybe there could be "When To Use Razor Pages" and "When To Use MVC" sections? Although "When To Use" may be a little strong. "Scenarios that lend themselves to Razor Pages"/MVC...? Wording is hard. 😆 |
That's all for my suggestions. Hope at least some of them are useful. Again - I really appreciate that you reached out to have me take a look at this @Rick-Anderson! |
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
MVC uses separate folders for Views, Controllers, and ViewModels when all three are tightly coupled. You must bounce between all three folders when you need to add/change/debug a feature. With Razor Pages, the `PageModel` (Controller + ViewModel) is in the same folder as the View. ~Hit F7 in Visual Studio to toggle between them.~ | ||
|
||
Razor Pages follow the [Single responsibility principle](https://wikipedia.org/wiki/Single_responsibility_principle), while MVC does not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Razor Pages follow the Single responsibility principle, while MVC does not.
I'd remove this.
aspnetcore/razor-pages/rp-mvc.md
Outdated
MVC uses separate folders for Views, Controllers, and ViewModels when all three are tightly coupled. You must bounce between all three folders when you need to add/change/debug a feature. With Razor Pages, the `PageModel` (Controller + ViewModel) is in the same folder as the View. ~Hit F7 in Visual Studio to toggle between them.~ | ||
|
||
Razor Pages follow the [Single responsibility principle](https://wikipedia.org/wiki/Single_responsibility_principle), while MVC does not. | ||
* **Unit Testing is easier.** With a Controller, you might have many Actions and some of the dependencies injected that are related to only one or two Actions. When unit testing a single Action, the dependencies must be mocked or passed in as null. With Razor Pages, the dependencies you inject in are 100% related to GET, POST, PUT, etc actions in the `PageModel`. Unnecessary dependency injection in MVC testing can be mitigated with the [Builder pattern](https://visualstudiomagazine.com/articles/2012/07/16/the-builder-pattern-in-net.aspx). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I would say this.
@davidfowl removed
Can we say anything about that? Unit testing typically doesn't require as many mocks? |
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
By [Scott Sauber](https://twitter.com/scottsauber) and [Rick Anderson](https://twitter.com/RickAndMSFT) | ||
|
||
Razor Pages is a feature of the ASP.NET Core framework. Razor Pages follows the [MVVM](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/mvvm) pattern. Developers and teams familiar with ASP.NET MVC development: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use the following relative URL instead: /xamarin/xamarin-forms/enterprise-application-patterns/mvvm
- ASP.NET MVC --> ASP.NET Core MVC
aspnetcore/razor-pages/rp-mvc.md
Outdated
|
||
Razor Pages can be added to controller/view projects. The controller-view approach to MVC may be preferred by larger teams. | ||
|
||
This article compares Razor Pages to controller/views for creating server rendered HTML. ASP.NET Core MVC controllers are used to build Web APIs. For example, a front-end like React, Angular, Vue, etc. would use ASP.NET MVC controllers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Hyphenate "server rendered"
- Web APIs --> web APIs
- ASP.NET MVC --> ASP.NET Core MVC
@danroth27 can you schedule time to complete this before end of FY? cc @tdykstra |
@danroth27 can I close this PR and turn it into a blog by me? It would start out saying this is not official, but my opinion. |
@Rick-Anderson Sure. |
@scottsauber closing PR and moved to https://github.com/Rick-Anderson/RP-vs-MVC where we can be more opinionated. |
@Rick-Anderson - sounds good! |
Fixes #3889
Public review URL
Internal review URL