From the course: ASP.NET MVC: Building for Productivity and Maintainability

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Using child actions to generate complex common markup

Using child actions to generate complex common markup

From the course: ASP.NET MVC: Building for Productivity and Maintainability

Start my 1-month free trial

Using child actions to generate complex common markup

- [Presenter] In the previous video I showed you how to create a custom HTML helper that provides a strongly typed way to render common HTML markup. That works great for those scenarios when you already have the data to be displayed, and you just want to centralize or reuse some mark up and view logic. In other cases, however, it may be overly complicated for the controller to get data to the view. Perhaps the most common case is the one we're looking at right here, where the cart is being rendered in the menu section of the layout. Note the particularly bad code smell on line 42, a reference to a global variable. And if I hit F12 to jump into the definition of this variable, I can see that this global static property is actually making its own database call. This code works; however, it's considered a code smell, because in the model view controller pattern, it's supposed to be the controller that's orchestrating when and how database calls are made, and what data makes it into the…

Contents