View components can now be invoked as tag helpers in ASP.NET.
- [Instructor] While view components themselves didn't change in 1.1, what changes they can now be invoked as a tag helper. To do this, they must be registered in ViewImports.cshtml, and it's the same way we registered the custom tag helpers. So you add the line, addTagHelper* for all of the view components that it finds and then the assemblyname. When you invoke them as a tag helper, Pascal-cased names are changed to lower-kebab-case.
So for example, our view component is named categories-as-menus view component. When you lower-kebab that as if it was on a shish kebab, it becomes, as what you see on your screen, categories-as-menus, dropping the view component suffix. And then the tags themselves start with vc. So we go back into our code. Our view component itself hasn't changed. There's the name, CategoriesAsMenusViewComponent.
We look at the ViewImports. Here on line 7, we have the addTagHelper. We actually added this again for the custom tag helper we wrote, but this same line is used to register the view components. And then when we want to use the view component, instead of having to call invoke, we can actually just write it as line 36, vc:categories-as-menus.
- Running and debugging ASP.NET Core applications
- Pros and cons of migrating existing applications to ASP.NET Core.
- Built-in dependency injection
- Environment awareness and app configuration
- Web host configuration and SSL
- View components invoked as tag helpers
- Configuration and logging
- Using Razor Pages
Skill Level Intermediate
Set up the sample projects4m 48s
1. Get to Know .NET Core
2. ASP.NET Core 1.0
3. ASP.NET Core 1.1
4. ASP.NET Core 2.0
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.