views:

90

answers:

4

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?

+1  A: 

I think you should better put your business logic into your domain model or into services. That way it's much more testable and reusable

chester89
+11  A: 

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 :)

Russ Cam
A: 

Without wishing to sound obvious, the HTML in HTMLHelper is a big clue as to the fact that this component is presentation focused. I would expect to find no business logic here, and purely HTML functionality (that, likely, could be reused in other projects?)

Brian Agnew
A: 

All your HTMLHelpers should allow being ported over to another assembly and be used across your org :)

Praveen