26. Using the Built-in Tag Helpers Flashcards

1
Q

What are Built-in Tag Helpers?

A

The built-in tag helpers perform commonly required transformations on HTML elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why are Built-in Tag Helpers useful?

A

Using the built-in tag helpers means you don’t have to create custom helpers using the techniques in Chapter 25.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are Built-in Tag Helpers used?

A

The tag helpers are applied using attributes on standard HTML elements or through custom HTML elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Are there any pitfalls or limitations to Built-in Tag Helpers?

A

No, these tag helpers are well-tested and easy to use. Unless you have unusual needs, using these tag helpers is preferable to custom implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Are there any alternatives to Built-in Tag Helpers?

A

These tag helpers are optional, and their use is not required.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are anchor elements and how to Transform Anchor Elements?

A
The a element is the basic tool for navigating around an application and sending GET requests to the application. The AnchorTagHelper class is used to transform the href attribute of a elements so they target URLs generated using the routing system, which means that hard-coded URLs are not required and a change in the routing configuration will be automatically reflected in the application’s anchor elements.
The asp-action and asp-controller attributes specify the name of the action method and the controller that defines it. Values for segment variables are defined using asp-route-[name] attributes, such that the asp-route-id attribute provides a value for the id segment variable that is used to provide an argument for the action method selected by the asp-action attribute.
Clicking the anchor elements will send an HTTP GET request that targets the Home controller’s Index method.

<a>
Select
</a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Using Anchor Elements for Razor Pages

A

The asp-page attribute is used to specify a Razor Page as the target for an anchor element’s href attribute. The path to the page is prefixed with the / character, and values for route segments defined by the @page directive are defined using asp-route-[name] attributes.

<a>Suppliers</a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the ScriptTagHelper class?

A

The ScriptTagHelper class is the built-in tag helper for script elements and is used to manage the inclusion of JavaScript files in views attributes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Globbing?

A

Globbing is a useful way of ensuring that a view includes the JavaScript files that the application requires, even when the exact path to the file changes, which usually happens when the version number is included in the file name or when a package adds additional files.

?
js/src?.js
This pattern matches any single character except /. The example matches any file contained in the js directory whose name is src, followed by any character, followed by .js, such as js/src1.js and js/srcX.js but not js/src123.js or js/mydir/src1.js.

*
js/*.js
This pattern matches any number of characters except /. The example matches any file contained in the js directory with the .js file extension, such as js/src1.js and js/src123.js but not js/mydir/src1.js.

**
js/**/*.js
This pattern matches any number of characters including /. The example matches any file with the .js extension that is contained within the js directory or any subdirectory, such as /js/src1.js and /js/mydir/src1.js.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the LinkTagHelper class?

A
The LinkTagHelper class is the built-in tag helper for link elements and is used to manage the inclusion of CSS style sheets in a view.
The LinkTagHelper shares many features with the ScriptTagHelper, including support for globbing patterns to select or exclude CSS files so they do not have to be specified individually.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the CacheTagHelper class?

A
The CacheTagHelper class allows fragments of content to be cached to speed up rendering of views or pages. The content to be cached is denoted using the cache element, which is configured using the attributes shown in Table 26-8. 
Note : Caching is a useful tool for reusing sections of content so they don’t have to be generated for every request. But using caching effectively requires careful thought and planning. While caching can improve the performance of an application, it can also create odd effects, such as users receiving stale content, multiple caches containing different versions of content, and update deployments that are broken because content cached from the previous version of the application is mixed with content from the new version. Don’t enable caching unless you have a clearly defined performance problem to resolve, and make sure you understand the impact that caching will have.

Following will cache the timestamp

        <h6 class="bg-primary text-white m-2 p-2">
            Cached timestamp: 
                @DateTime.Now.ToLongTimeString()
        </h6>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly