This article is about custom html helpers methods in asp.net mvc.There are two kinds of custom html helpers methods in asp.net mvc those are
1. Inline Helper Method
2. External Helper Method
The Inline helper can be defined and call it as shown below
In the above image i defined an inline helper called print using @helper tag and i called it twice using by passing an arguments "Human" and "Machine".
The external helper is defined in the extension method. The extension method is used to extend the existing type with new methods, without altering the existing type. The first parameter of the extension method contains the this modifier with the extended type in our case HtmlHelper type. The return type of the external helper method should be MvcHtmlString.
In the above extension method i used tag builder to build the html string and sent it to the view for rendering.
Call External Helper:
In the above code to call the external helper method, I import the external helper namespace and call the external helper method with the proper arguments.