I asked this question earlier about business logic and presentation logic, and it got me thinking.. I think it’s easier to spot questionable practice when looking at code in a View because I’m automatically suspicious when I see it. Usually it’s ok because it’s presentation logic, but I always tend to look closer.
But I don’t look as close when it’s in a HTML helper. In fact, I know I’ve done it before and I’ve told others to move the business logic into a Helper. But is that right?
My guess now is that it’s not.. I think the job of the helper is the same as the job of the view. Presentation only. What do you guys think?
The HtmlHelper should be concerned only with outputting the relevant html into your view and should not have knowledge of any business rules. This should be done in your business layer / domain model layer.
The question you need to ask yourself is, “If I took the HtmlHelper out of the current application and put it into another MVC application, could it be reused without modification?”. If the answer is no, there’s a good chance it knows too much 🙂