Use View Components, not Partial Views, in ASP.NET Core

preview_player
Показать описание


Why use View Components and not Partial Views? The biggest reason is that when inserting a Partial View into a Razor page, all the ViewData associated with the calling View is automatically associated with the Partial View. This means that a Partial View may behave very differently on one Razor page than on another. With View Components, you control what gets shared to your View Components.
Рекомендации по теме
Комментарии
Автор

Excellent explanation. Thanks to that I decided to buy Peter's course about ASP.NET Core Tag Helpers and View Components on Pluralsight. I recommend.

sulmarpl
Автор

Thanks Peter! I was looking around for a simple explanation of view component in Razor and YT land this in my search... lucky me 🙂

ssirois
Автор

Excellent video and very helpful. It's fantastic that it has an accompanying blog + git repository. Well done, thank you!

Tolg
Автор

This works great! I agree it is nicely self-contained and easy to work with. Thank you!

ganjalaw
Автор

Thanks for this video, very succinct!

DavidHouseGA
Автор

Nice explanation
Thanks and
Greeting from the desert

HA-fqxc
Автор

AARGH!!! I have been driving myself crazy! I am new to Razor Pages and am migrating a large application that extensively used nested ascx pages where a nested page would call a second nested page while passing objects forward. I can see no way of getting OnGet() on a nested view or Razor Page to be called, nor can I pass a variable or even call a child method from a parent method. Please can you spread some light on this?

spauldingcanada
Автор

how can you refresh a view component using javascript

szafar
Автор

This makes no damn sense if you still have to use js.... whats the difference between using an ajax request and hitting a controller and using a partial view and then injecting the returned html into the proper dom element?

can I somehow create a component thats for example, something like
<vc:list-notes notes-on-page=variable>
</vc:list-notes>

and on that page when i change the value of variable, it hits the view component and loads what it needs to that way... or does this still require js?

chadgregory
Автор

So, ViewComponent is killer because encapsulation and no side effects...
If that's supposed to be convincing, then what's an example of a side effect in a partial view?

weBeatMedicare
Автор

Other than being 'invoked' automatically, this video doesn't explain fully why a partial view cannot be used in place of another one of those MS additional-useless-feature called ViewComponent. If Microsoft developed what they think now is a useless partial view, now they're using another soon-to-be useless ViewComponent.

STUPIDYOUTUBE_HIDINGMSGS
Автор

Why not use BLAZOR ??? it does exactly this with much ease!

hqcart
Автор

Using View Components everywhere is overkill and completely unnecessary. They each have their correct situational usage. Using either one everywhere is just wrong.

NBGTFO
visit shbcf.ru