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
From the course: ASP.NET MVC: Building for Productivity and Maintainability
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…
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
-
-
-
-
-
Using extension methods to remove magic strings5m 30s
-
(Locked)
Using extension methods to strongly type common actions4m 38s
-
(Locked)
Creating custom HTML helpers to reduce and reuse markup6m 16s
-
(Locked)
Using child actions to generate complex common markup4m 59s
-
(Locked)
Challenge: Use a child action to make a smarter HTML helper1m 29s
-
(Locked)
Solution: Use a child action to make a smarter HTML helper4m 16s
-
-
-
-
-
-