Html Helpers

Html helpers are like functions/methods, they are pretty easy to create and very useful.

Helpers can be created in a complete different view called “HtmlHelpers.cshtml” for example. But for the sake of this post ill add it to my  current view.

<h1>Helper view</h1>
@helper MyCustomHelper(string name, string place) {
Hi <span style="background-color:#dddbdb">@name</span> !
Welcome to : <span style="background-color:#dddbdb">@place</span>

@MyCustomHelper(name:"Dev" , place: "public string notes")

“MyCustomHelper” its pretty self explanatory, it has 2 string which can be used witht the usual “@”.

The result:


Now if you need to clone this block, just call the method and send another string as param, no need to write more code. Keep it DRY.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s