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.

Reuse view logic with injectable services

Reuse view logic with injectable services

From the course: Learning ASP.NET Core MVC

Start my 1-month free trial

Reuse view logic with injectable services

- [Instructor] By this point in the course, I've shown you several different HTML helper methods and you've accessed these helpers from the special HTML and URL properties in the view and trust me, the more you use asp.net Core MVC, the more you're going to want to create your own helpers and custom properties and in this video, that's exactly what I'm going to show you how to do. For a good example of the need for a custom helper method, take a look at how we're rendering the posted date property. When we leave it up to razor to render it, it ends up displaying some long string with a time including seconds and everything. But what if we only wanted to display the date? We could change the code in this one place to make that happen and that's all well and good, but what if we applied this approach all over our application and then we wanted to change the way that we displayed all of our dates, wherever they're rendered? Well, then we'd have to search for all those references and…

Contents