How are tag helpers different from the Helper class?
2 answers
Tag Helpers were introduced for several reasons. Scott Hanselm talks about this in detail here . However, in themes for tag helpers:
Front-end developers don't need knowledge of C # to write them.
This is actually not very intuitive for a traditional outside developer.
@Html.LabelFor(m => m.Title, new { @class = "control-label" })
@Html.TextBoxFor(m => m.Title, new { @class = "form-control" })
However, this is made a lot clearer with tag helpers:
<label asp-for="Title" class="control-label" />
<input asp-for="Title" class="form-control" />
Note that this was the last checkbox I checked, including asp-
whether to use a prefix or not.
This makes it easy to add other attributes such as class
, placeholder
or even other custom attributes.
I am using angular.js with my projects; for this, the syntax becomes even more confusing:
@Html.TextBoxFor(m => m.Title, new { @class = "form-control", ng_model = "ctrl.title" })
Now it's as easy as adding an attribute as expected:
<input asp-for="Title" class="form-control" ng-model="ctrl.title" />
You can even write your own.
I won't go into the details, but you can create expandable server side widgets that might even match your client frameworks for SEO purposes. There's a pretty decent tutorial for creating helper tags .
+4
source to share