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.

Creating reusable components with view components

Creating reusable components with view components

From the course: Learning ASP.NET Core MVC

Start my 1-month free trial

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…

Contents