I am trying to refactor my views a bit and up til now i have been using the built HTML helpers but i thought i would create my own – they’re extension methods right?
I wonder if anyone can confirm or give advise when an HTML is needed? I think i once saw a document that said if you use 1 IF statement in your views encapsulate it into a html helper – would anyone agree with that?
With regards to creating html helpers, would it be better to create my own class rather than add extension methods to the HTML class that ships with MVC? Any body have ideas on this?
Or possible i shouldn’t bother with HTML helpers and just use the built in ones and continue to use my IF statements within views.
Thanks in advance
Use HTML helpers when you want to encapsulate the output of a piece of HTML markup that can take varying values.
I’d recommend creating them as extension methods to
HtmlHelperrather than creating your own class, as your own class won’t be available inside of the defaultViewPagewithout either instantiating a new instance inside of the View or subclassingViewPageand using this in the View (or passing in on the model, but that’s just wrong!).