Are custom helper classes customizing the ASP.NET MVC model?

In the related article, I mentioned that I found custom HTML helpers to be just such useful in development. For example, when I need paging for the "grid", I have a user assistant that I can call Html.Pager() .

Some of them noted that HTML helpers are a violation of the MVC model. Personally, I don’t see it different from existing helpers such as Html.Textbox() or Html.ActionLink() .

I'm still trying to learn more about MVC, so all prospects are welcome.

+6
c # model-view-controller theory asp.net-mvc html-helper
source share
1 answer

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

So, in general, this is not a violation of the MVC model. I think it really depends on what you do in your assistant. Helpers should simply display html based on the arguments passed to them. They should not access data, etc.

They simply encapsulate code to render the common parts of the markup. If you do this, then you are not breaking the ASP.NET MVC model.

+16
source share

All Articles