views:

675

answers:

2

I'm looking to build an reusable control or custom helper for my MVC project. I'm sure there is a best practice for this. Any help is appreciated.

+7  A: 

Sure, the best practices are encapsulated in the HtmlHelpers and other helpers in the MVC source code. You can get the source at http://www.codeplex.com/aspnet

Scott Hanselman
That's it? Wow. I was surely making things more complex than it had to be. Thanks Scott!
Jason N. Gaylord
A: 

(Hate to disagree with you Scott) Using HtmlHelpers is not a best practice. It is not a practice that has been sharpened through use on real projects and is only one approach. I have recently written a little post on using SubControllers.. we use HtmlHelpers for some small things, but we use SubControllers for greater control, composition and dependency inversion.

Matt Hinze
Matt, I could argue that HtmlHelpers are the MSFT way of creating controls and that they would recommend going that route. Whether or not it's been widely adopted is another story. Thanks for the additional link though!
Jason N. Gaylord
Jason, you absolutely could argue that. You could also argue that about DataSets but now even MS is abandoning them.
Matt Hinze
Matt - how are subcontrollers, called from a view, following the MVC pattern? HTML Helpers and Partial Views are standard, but I'd say that subcontrollers (at least how your team has implemented them) stand on shaky ground.
Jess
we've actually abandoned subcontrollers at this point. currently we're using renderaction and renderpartial and htmlhelper extensions (to codify renderaction/renderpartial calls)
Matt Hinze