You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Put in more reasonable cache times for examples.
* Added to ImageTagHelper.md a block on the top and guessed at updating assetid by incrementing 1. Renamed all Additional Resources to Resources per @Devguard, fixed incorrect expires-sliding code example, removed warning about Cache NeverRemove.
* fixed blank lines below toc entry, made consistent "Additional resources", put back in warning about NeverRemove based on feedback from team: #2698 (comment)
* clean up
* created Distributed and Environment Tag Helper Doc Pages and worked on environment.
* Reworked sections from @Rick-Anderson previous commit and removed review comments.
* Updated Anchor Tag Helper's definition of asp-action and asp-controller to be more explicit about defaults as well as say "href" instead of "final URL".
* I realized that asp-all-route-data also behaves like asp-route-* with routing parameters so I updated the doc to reflect that.
* Updated var-by-route definition following comments from Damien in old github post aspnet/Mvc#1552
* Cleanup of Tag Helper Docs
* changed author to pkellner from Peter Kellner per @mairaw
* Update AnchorTagHelper.md
* Update CacheTagHelper.md
* Minor tweaks
The Anchor Tag Helper enhances the HTML anchor (`<a ... ></a>`) tag by adding new attributes. The link generated (on the `href` tag) is created using the new attributes. That URL can include an optional protocol such as https.
20
20
21
-
The Anchor Tag Helper enhances the html anchor (`<a ... ></a>`) tag. A new set of attributes are defined that work with the anchor tag. The link generated (on the `href` tag) is based on a combination of these new attributes that work together to form the final URL. That URL can include an optional protocol such as https.
22
-
23
-
The speaker controller used in attribute definitions below is shown here.
21
+
The speaker controller below is used in samples in this document.
24
22
25
23
<br/>
26
24
**SpeakerController.cs**
@@ -34,51 +32,126 @@ The speaker controller used in attribute definitions below is shown here.
34
32
35
33
### asp-controller
36
34
37
-
`asp-controller` is used to associate which controller will be used to generate the final URL. The only valid choices are controllers that exist in the current project. To get to a list of all speakers specifying `asp-controller="Speaker"` is required. If only the `asp-controller` and no `asp-action` is specified, the default asp-action will be the name of the the controller method calling this view page.
35
+
`asp-controller` is used to associate which controller will be used to generate the URL. The controllers specified must exist in the current project. The following code lists all speakers:
If the `asp-controller` is specified and `asp-action` is not, the default `asp-action` will be the default controller method of the currently executing view. That is, in the above example, if `asp-action` is left out, and this Anchor Tag Helper is generated from *HomeController*'s `Index` view (**/Home**), the generated markup will be:
48
+
49
+
50
+
```html
51
+
<ahref="/Home">All Speakers</a>
52
+
```
38
53
39
54
- - -
40
55
41
56
### asp-action
42
57
43
-
`asp-action` is the name of the method in the controller that will be included in the final URL. That is, in the example, if the route to the Speaker Detail page is wanted, then the attribute should be set to `asp-action=Detail`. You should always set `asp-controller` when specifying `asp-action`. If no `asp-action` is specified then the default `asp-controller` will be the current executing controller.
58
+
`asp-action` is the name of the action method in the controller that will be included in the generated `href`. For example, the following code set the generated `href` to point to the speaker detail page:
If no `asp-controller` attribute is specified, the default controller calling the view executing the current view will be used.
71
+
72
+
If the attribute `asp-action` is `Index`, then no action is appended to the URL, leading to the default `Index` method being called. The action specified (or defaulted), must exist in the controller referenced in `asp-controller`.
44
73
45
74
- - -
46
75
47
76
### asp-route-{value}
48
77
49
-
`asp-route-` is a wild card route prefix. Any value you put after the trailing dash will be interpreted as the parameter to pass into the route. For example, if a tag is created as follows:
78
+
`asp-route-` is a wild card route prefix. Any value you put after the trailing dash will be interpreted as a potential route parameter. If a default route is not found, this route prefix will be appended to the generated href as a request parameter and value. Otherwise it will be substituted in the route template.
79
+
80
+
Assuming you have a controller method defined as follows:
81
+
82
+
```csharp
83
+
publicIActionResultAnchorTagHelper(stringid)
84
+
{
85
+
varspeaker=newSpeakerData()
86
+
{
87
+
SpeakerId=12
88
+
};
89
+
returnView(viewName, speaker);
90
+
}
91
+
```
92
+
93
+
And have the default route template defined in your **Startup.cs** as follows:
The **cshtml** file that contains the Anchor Tag Helper necessary to use the **speaker** model parameter passed in from the controller to the view is as follows:
The generated HTML will then be as follows because **id** was found in the default route.
56
116
57
-
This is because a route was found that matched a single parameter "id" in the ```SpeakerController``` method ```Detail```. If there was no parameter match, say for example you created the tag helper
If either `asp-controller` or `asp-action` are not specified, then the same default processing is followed as is in the `asp-route` attribute.
66
139
67
140
- - -
68
141
69
142
### asp-route
70
143
71
144
`asp-route` provides a way to create a URL that links directly to a named route. Using routing attributes, a route can be named as shown in the `SpeakerController` and used in its `Evaluations` method.
72
145
73
-
`Name = "speakerevals"` tells the Anchor Tag Helper to generate a route directly to that controller method using the URL `/Speaker/Evaluations`. If `asp-controller` or `asp-action` is specified in addition to `asp-route`, the route generated may not be what you expect. `asp-route` should not be used with either of the attributes `asp-controller` or `asp-action` to avoid a route conflict.
146
+
`Name = "speakerevals"` tells the Anchor Tag Helper to generate a route directly to that controller method using the URL `/Speaker/Evaluations`. If `asp-controller` or `asp-action` is specified in addition to `asp-route`, the route generated may not be what you expect. `asp-route` should not be used with either of the attributes `asp-controller` or `asp-action` to avoid a route conflict.
74
147
75
148
- - -
76
149
77
150
### asp-all-route-data
78
151
79
-
`asp-all-route-data` allows creating on a .NET context (that is, the running C# associated with your Razor view) a dictionary of key value pairs where the key is the parameter name and the value is the value associated with that key.
152
+
`asp-all-route-data` allows creating a dictionary of key value pairs where the key is the parameter name and the value is the value associated with that key.
80
153
81
-
As the example below shows, an inline dictionary is created and the data is passed to the razor view. The data could also be passed in with your model to keep the Razor view simpler.
154
+
As the example below shows, an inline dictionary is created and the data is passed to the razor view. As an alternative, the data could also be passed in with your model.
82
155
83
156
```
84
157
@{
@@ -93,39 +166,40 @@ As the example below shows, an inline dictionary is created and the data is pass
When the link is clicked, this will call the controller method `EvaluationsCurrent` because that controller has two string parameters that match what has been created from the `asp-all-route-data` dictionary.
175
+
When the link is clicked, the controller method `EvaluationsCurrent` is called. It is called because that controller has two string parameters that match what has been created from the `asp-all-route-data` dictionary.
176
+
177
+
If any keys in the dictionary match route parameters, those values will be substituted in the route as appropriate and the other non-matching values will be generated as request parameters.
103
178
104
179
- - -
105
180
106
181
### asp-fragment
107
182
108
-
`asp-fragment` defines a URL fragment to append to the URL. The Anchor Tag Helper will add the hash character (#) automatically. If you create a tag:
183
+
`asp-fragment` defines a URL fragment to append to the URL. The Anchor Tag Helper will add the hash character (#). If you create a tag:
Hash tags are useful when doing clientside applications. They can be used for easy marking and searching in JavaScript for example.
196
+
Hash tags are useful when building client-side applications. They can be used for easy marking and searching in JavaScript, for example.
123
197
124
198
- - -
125
199
126
200
### asp-area
127
201
128
-
`asp-area` sets the area name that ASP.NET Core uses to set the appropriate route. Below are examples of how the area attribute causes a remapping of routes. Setting `asp-area` to Blogs prefixes the directory Areas/Blogs to the routes of the associated controllers and views for this anchor tag..
202
+
`asp-area` sets the area name that ASP.NET Core uses to set the appropriate route. Below are examples of how the area attribute causes a remapping of routes. Setting `asp-area` to Blogs prefixes the directory `Areas/Blogs` to the routes of the associated controllers and views for this anchor tag.
129
203
130
204
* Project name
131
205
@@ -170,19 +244,19 @@ The generated HTML will include the areas segment and will be as follows:
170
244
171
245
### asp-protocol
172
246
173
-
The `asp-protocol` is for specifying a particular protocol (such as `https`) in your URL. An example Anchor Tag Helper that includes the protocol will look as follows.
247
+
The `asp-protocol` is for specifying a protocol (such as `https`) in your URL. An example Anchor Tag Helper that includes the protocol will look as follows:
0 commit comments