From the course: ASP.NET MVC: Building for Productivity and Maintainability
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Using extension methods to strongly type common actions
From the course: ASP.NET MVC: Building for Productivity and Maintainability
Using extension methods to strongly type common actions
- [Instructor] Now that I've already showed you how to use extension methods to replace magic strings in your application in this video I'm going to leverage that same exact approach of centralizing logic in extension methods, however, this time I'm going to create a strongly typed wrapper around the Url.action Url helper method to not only reduce the number of magic strings, but also the amount of duplicate codes scattered throughout my application. In order to demonstrate the problem and make it easier to fix I'll start by doing a global search for all the times the Url helper is used to generate links to a product page. As the search results show this same code is used in several places throughout the site complete with its magic strings. To fix this I'll start out like last time by creating an extension class. This time I'll name it UrlHelperExtensions. Then I'll create the static extension method named product which extends the system.web.MVC.Url helper class. This method is…
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
-
-
-
-
-
-