To expose all of the Tag Helpers in this project (which creates an assembly named AuthoringTagHelpers), you would use the following: *, *, AuthoringTagHelpers is the assembly for the built-in ASP.NET Core Tag Helpers. The first parameter after specifies the Tag Helpers to load (we are using "*" for all Tag Helpers), and the second parameter "" specifies the assembly containing the Tag Helpers. The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly ( ) will be available to every view file in the Views directory or subdirectory. ![]() In this case, the view file is Pages/_ViewImports.cshtml, which by default is inherited by all files in the Pages folder and subfolders making Tag Helpers available. The directive makes Tag Helpers available to the view. If you create a new ASP.NET Core web app named AuthoringTagHelpers, the following Views/_ViewImports.cshtml file will be added to your project: *, *, AuthoringTagHelpers Tag Helpers scope is controlled by a combination of and the "!" opt-out makes Tag Helpers available See Author Tag Helpers for more information. The asp-for attribute is made available by the For property in the LabelTagHelper. Consider a Razor view with the following model: public class Movie This attribute extracts the name of the specified model property into the rendered HTML. For example, the element used in many views in the Views/Account folder contains the asp-for attribute. Most built-in Tag Helpers target standard HTML elements and provide server-side attributes for the element. ![]() This robustness and labor savings comes essentially free by using the ImageTagHelper. Clients are guaranteed to get the current image. The ImageTagHelper can append a version number to the image name, so whenever the image changes, the server automatically generates a new unique version for the image. Not only is this very labor intensive, it's also error prone (you could miss a reference, accidentally enter the wrong string, etc.) The built-in ImageTagHelper can do this for you automatically. Historically, after an image was edited, the name had to be changed and each reference to the image in the web app needed to be updated. Images should be aggressively cached for performance reasons, and unless you change the name of an image, you risk clients getting a stale copy. Even developers experienced with Razor C# syntax are more productive using Tag Helpers than writing C# Razor markup.Ī way to make you more productive and able to produce more robust, reliable, and maintainable code using information only available on the serverįor example, historically the mantra on updating images was to change the name of the image when you change the image. IntelliSense support for Tag Helpers explains the IntelliSense environment. Tag Helpers compared to HTML Helpers explains the differences in more detail. This is in sharp contrast to HTML Helpers, the previous approach to server-side creation of markup in Razor views. Front-end designers conversant with HTML/CSS/JavaScript can edit Razor without learning C# Razor syntax.Ī rich IntelliSense environment for creating HTML and Razor markup ![]() What Tag Helpers provideįor the most part, Razor markup using Tag Helpers looks like standard HTML. For more information, see ASP.NET Core Razor components. ![]() Tag Helpers aren't supported in Razor components. In many cases, HTML Helpers provide an alternative approach to a specific Tag Helper, but it's important to recognize that Tag Helpers don't replace HTML Helpers and there's not a Tag Helper for each HTML Helper. If you're familiar with HTML Helpers, Tag Helpers reduce the explicit transitions between HTML and C# in Razor views. For example, the built-in LabelTagHelper can target the HTML element when the Tag Helpers are authored in C#, and they target HTML elements based on element name, attribute name, or parent tag. There are many built-in Tag Helpers for common tasks - such as creating forms, links, loading assets and more - and even more available in public GitHub repositories and as NuGet packages. Whenever the image changes, the server generates a new unique version for the image, so clients are guaranteed to get the current image (instead of a stale cached image). For example, the built-in ImageTagHelper can append a version number to the image name. Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |