views:

1313

answers:

1

On a related post I mentioned that I have found custom HTML helpers to be just that, helpful, when developing. For instance, when I need paging for a "grid" I have a custom helper that I can call --> Html.Pager()

Some have made a point that HTML helpers are a violation of the MVC model. Personally, I don't see it being any different than the existing helpers, such as Html.Textbox() or Html.ActionLink().

Im still trying to learn more about MVC, so all perspectives are appreciated.

+14  A: 

Notice that the existing helpers are all written as extension methods of the HtmlHelper class. We explicitly took that approach so that others can write their own helper methods as extension methods of HtmlHelper.

So in general, this is not a violation of the MVC model. I guess it really depends on what you are doing in your helper. Helpers should simply render html based on arguments passed into them. They shouldn't do any data access, etc...

They merely encapsulate code for rendering common pieces of markup. If you're doing that, then you're not in violation of the ASP.NET MVC model.

Haacked
So what is the best way to render common pieces of an application with data access or any other thing more than rendering Html.In MVC 2 we have Html.RenderAction, it is probably the best way, since it comes from the controller, but in MVC 1?
Alper Ozcetin