Custom Html Helpers Methods



This article is about custom html helpers methods in mvc.There are two kinds of custom html helpers methods in mvc those are

1. Inline Helper Method

2. External Helper Method

Inline Helper:

The Inline helper can be defined  and call it as shown below

Inline Helper

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".

External Helper:

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.

External Helper One

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:

External Helper Two

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.


Average Rating: 0.00 by 0 users
Giri Prasad
Download PDF
Download Project