I’m creating a set of helpers for rendering compatible Twitter Bootstrap html. As I see it, I have two options when it comes to how to group these methods together:
- Extend the HtmlHelper prefixing the methods with TB
- Create a new class
TBootHelperwhich contains the methods
In the second case, to get the TBoot helper available, the developer would add
<pages pageBaseType="Twitter.Bootstrap.Mvc.TBootViewPage">
To it’s ~/Views/web.config (as pointed by @darin)
Or instantiate the helper when it’s needed
@using Twitter.Bootstrap.Mvc
var TBoot = new TBootHelper<TModel>(Html);
My question is, Should I create a TBootHelper class or just add methods to the HtmlHelper?
I’d go with creating a custom
TBootHelperand a custom base view that all views will inherit from and which will have a property of typeTBootHelper.And instead of forcing the developer to add
@inherits Twitter.Bootstrap.Mvc.TBootViewPage<TModel>to every single Razor template in which he wants to use this custom helper, I would add it to the~/Views/web.configfile, once and for all:and then in the views: