Custom Html Helpers Methods

(ASP.NET MVC)


Hi,

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

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.


Ratings


Average Rating: 0.00 by 0 users
Giri Prasad
6/20/2015
6/20/2015
Download PDF
Download Project

Comments