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()
.
I'm still trying to learn more about MVC, so all perspectives are appreciated.
HTML Custom Helpers HTML helper is a method that returns a HTML string. Then this string is rendered in view. MVC provides many HTML helper methods. It also provides facility to create your own HTML helper methods. Once you create your helper method you can reuse it many times.
HTML Helpers are managed within View to execute HTML content. We can use HTML Helpers to implement a method that returns a string. This tutorial discusses how you can define or create custom HTML Helpers that you can use within your MVC views.
An HTML Helper is just a method that returns a HTML string. The string can represent any type of content that you want. For example, you can use HTML Helpers to render standard HTML tags like HTML <input>, <button> and <img> tags etc.
Tag Helpers are attached to HTML elements inside your Razor views and can help you write markup that is both cleaner and easier to read than the traditional HTML Helpers. HTML Helpers, on the other hand, are invoked as methods that are mixed with HTML inside your Razor views.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With