Aspnetcore.docs: How useful "Partial Views" compared to "View Components" ?

Created on 31 Jul 2018  Â·  1Comment  Â·  Source: dotnet/AspNetCore.Docs

In this article it's said that View Components are much more powerful than Partial Views and they are better for complex logic such as: Login panel, Shopping cart etc. However when I started a project in .Net Core 2.1 with a authentication it has generated the "login panel" as partial view and it seems preety good to me and looks much more organized than View Component. My question is would it be ok trying to solve "complex logic" stated in this article with Partial Views if I feel comfortable with it, or is it really hurts the performance and maintainablity ?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Source - Docs.ms

Most helpful comment

@brainoverflow98 One big advantage of view components over partial views is testability. Separation of concerns is enforced, so it's simple to unit test a view component. The biggest problem I've seen with partial views is that business logic makes its way into the partial view. Separation of concerns is no longer enforced, and testability suffers as a result.

If you feel comfortable with it, there's nothing that prevents you from using a partial view. Keep in mind that maintainability could suffer as a result of that decision. There's very little logic in the login panel of the project template, so a partial view works great.

>All comments

@brainoverflow98 One big advantage of view components over partial views is testability. Separation of concerns is enforced, so it's simple to unit test a view component. The biggest problem I've seen with partial views is that business logic makes its way into the partial view. Separation of concerns is no longer enforced, and testability suffers as a result.

If you feel comfortable with it, there's nothing that prevents you from using a partial view. Keep in mind that maintainability could suffer as a result of that decision. There's very little logic in the login panel of the project template, so a partial view works great.

Was this page helpful?
0 / 5 - 0 ratings