Section 17 — Tag Helpers
Tag Helpers
Tag helpers are the classes that can be invoked as an html tag or html attribute.
They generate a html tag or adds values into attributes of existing html tags.
Tag Helpers for ,
- asp-controller
- asp-action
- asp-route-x
- asp-route
- asp-area
Tag Helpers for ,
- asp-for
Tag Helpers for ,
Route URLs’ will be re-generated for and tags;
It generates the url as “controller/action” pattern.
Tag Helpers for ![]()
- asp-append-version
Tag Helpers for
- asp-validation-for
Tag Helpers for
- asp-fallback-src
- asp-fallback-test
Tag Helpers for
- asp-validation-summary
Tag Helpers for
will be converted as:
asp-controller and asp-action
Generates route url for the specified action method with “controller/action” route pattern.
Tag Helpers for
will be converted as:
asp-controller and asp-action
Generates route url for the specified action method with “controller/action” route pattern.
Tag Helpers for and
will be converted as:
asp-route-x
Specifies value for a route parameter, which can be a part of the route url.
Tag Helpers for , <input asp-for="ModelProperty" />
will be converted as:
asp-for
Generates “type”, “name”, “id”, “data-validation” attributes for the ,
Tag Helpers for <label>
will be converted as:
asp-for
Generates “for” attribute for the
Client Side Validations
Data annotations on model properties
[Required]
publicDataTypePropertyName { get; set; }“data-*” attributes in html tags [auto-generated with “asp-for” helper]
Import jQuery Validation Scripts
https://cdnjs.cloudflare.com/ajax/libs/ jquery/3.6.0/jquery.min.js
https://cdnjs.cloudflare.com/ajax/libs/ jquery-validate/1.19.3/jquery.validate.min.js
https://cdnjs.cloudflare.com/ajax/libs/ jquery-validation-unobtrusive/3.2.12/ jquery.validate.unobtrusive.min.js
Tag Helpers for ![]()
asp-append-version
- Generates SHA512 hash of the image file as query string parameter appended to the file path.
- It REGENERATES a new hash every time when the file is changed on the server. If the same file is requested multiple times, file hash will NOT be regenerated.
Tag Helpers for
<script src="CDNUrl" asp-fallback-src="~/LocalUrl" asp-fallback-test="object">
<script> object || document.write("<script src='/LocalUrl'></script>"); </script>
<script> object || document.write("<script src='/LocalUrl'></script>"); </script>asp-fallback-src
- It makes a request to the specified CDNUrl at the “src” attribute.
- It checks the value of the specified object at the “asp-fallback-test” tag helper.
• If its value is null or undefined (means, the script file at CDNUrl is not loaded), then it makes another request to the LocalUrl through another script tag.