From the course: Learning ASP.NET Core MVC
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Enhancing a view component with logic and dynamic markup
From the course: Learning ASP.NET Core MVC
Enhancing a view component with logic and dynamic markup
- [Instructor] In the previous video, I showed you how to create and render a basic view component that rendered some basic string content. But now that those basics are out of the way, let's spice it up a little. As I built the view component class, I called out how it resembles a controller class and that's exactly how you should think of it, like a mini controller action, executing whenever you reference the view component. That means a few things, first you'll probably want to return a view from the invoke action, rather than static content. You do that by using the view helper method on the view component base class, and just like in the controller action, when you do this you'll need to change the return type to an action result type rather than a simple string. An IView component result type to be exact. The other great thing that view component classes share with controllers, is that you are able to inject application logic using dependency injection. For instance, in this…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Reuse view markup with partial views4m 13s
-
(Locked)
Reuse view logic with injectable services3m 16s
-
(Locked)
Creating reusable components with view components4m 51s
-
(Locked)
Enhancing a view component with logic and dynamic markup4m 15s
-
(Locked)
Avoid page refreshes with partial rendering5m 8s
-
(Locked)
-
-