Tag Helpers in ASP.Net Core

ASP.NET is quite a good framework for web applications. I enjoy working with it. Although it is not the only one I use, I have been building great things using it over the last couple of years.
Recently, a new Razor edition has been introduced under the name of Tag Helpers.
It aims at making the code more readable by not having to use Html Helpers when all we want is to create Form elements.

Screen Shot 2016-05-05 at 8.52.21 AM

The picture above shows an ASP tag helper of type asp-action. This defines which action s the form going to execute. Another type of tag helper is the environment one, which can be used to configure our application in Development mode or not. The following figure shows it.

Screen Shot 2016-05-05 at 8.54.25 AM.png

The code below will add the specified links if the application is running in Development mode. The environment tag acts as an if/else statement.

Here is the Html Helper for creating a label. Screen Shot 2016-05-05 at 9.03.56 AM

Here is the same label created using Tag Helpers.Screen Shot 2016-05-05 at 9.04.25 AM

We can see how the later is pretty clear.

We get the Tag Helpers referenced in our code, by convention, by having them added in the ViewImports.cshtml file as show below.

Screen Shot 2016-05-05 at 9.08.47 AM.png

This ends part 1. Part 2 will show how to create your own Tag Helpers.


Source

Channel9 video – https://channel9.msdn.com/Shows/Web-Hack-Wednesday/Tag-Helpers-in-ASPNet-Core

 

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s