From the course: Learning ASP.NET Core MVC
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Creating reusable components with view components
From the course: Learning ASP.NET Core MVC
Creating reusable components with view components
- [Instructor] At this point in the course, I've shown you how to create controllers that contain the application logic, views that contain the mark up that the user sees, and even ways to re-use that mark up in the form of layouts and partial views. But there's one scenario that isn't easily solved by these features, to find a good example of this we have to look no further than the home page of our sample application. See this section labeled monthly specials? In the left-hand column? That section is currently just hard coded HTML in our layout, but if it had a real implementation it would involve going to the database and grabbing the latest monthly specials. Now if that were in a normal view that would be no problem, since the controller would simply retrieve the required data, and pass it to the view. However since this markup is in our layout, every single action that implemented this layout would have to know how to get these monthly specials. This would not only be terribly…
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)
-
-