2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
using System ;
5
+ using System . Collections . Generic ;
5
6
using System . Linq ;
6
7
using Microsoft . AspNet . Mvc . Rendering ;
7
- using Microsoft . AspNet . Mvc . TagHelpers . Internal ;
8
8
using Microsoft . AspNet . Razor . Runtime . TagHelpers ;
9
9
10
10
namespace Microsoft . AspNet . Mvc . TagHelpers
@@ -17,9 +17,6 @@ public class AnchorTagHelper : TagHelper
17
17
{
18
18
private const string RouteAttributePrefix = "route-" ;
19
19
20
- [ Activate ]
21
- private ViewContext ViewContext { get ; set ; }
22
-
23
20
[ Activate ]
24
21
private IHtmlGenerator Generator { get ; set ; }
25
22
@@ -82,13 +79,18 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
82
79
{
83
80
TagBuilder tagBuilder ;
84
81
85
- var prefixedValues = TagHelperOutputHelper . PullPrefixedAttributes ( RouteAttributePrefix , output ) ;
82
+ var prefixedValues = output . PullPrefixedAttributes ( RouteAttributePrefix ) ;
83
+
84
+ Dictionary < string , object > routeValues = null ;
86
85
87
- // Generator.GenerateActionLink || GenerateRouteLink does not accept a Dictionary<string, string> for
88
- // route values.
89
- var routeValues = prefixedValues . ToDictionary (
90
- attribute => attribute . Key . Substring ( RouteAttributePrefix . Length ) ,
91
- attribute => ( object ) attribute . Value ) ;
86
+ if ( prefixedValues . Any ( ) )
87
+ {
88
+ // Generator.GenerateActionLink || GenerateRouteLink does not accept a Dictionary<string, string> for
89
+ // route values.
90
+ routeValues = prefixedValues . ToDictionary (
91
+ attribute => attribute . Key . Substring ( RouteAttributePrefix . Length ) ,
92
+ attribute => ( object ) attribute . Value ) ;
93
+ }
92
94
93
95
if ( Route == null )
94
96
{
@@ -122,40 +124,40 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
122
124
htmlAttributes : null ) ;
123
125
}
124
126
125
- TagHelperOutputHelper . MergeAttributes ( tagBuilder , output ) ;
127
+ output . MergeAttributes ( tagBuilder ) ;
126
128
}
127
129
}
128
130
129
131
private void RestoreBoundHtmlAttributes ( TagHelperContext context , TagHelperOutput output )
130
132
{
131
133
if ( Action != null )
132
134
{
133
- TagHelperOutputHelper . RestoreBoundHtmlAttribute ( nameof ( Action ) , context , output ) ;
135
+ output . RestoreBoundHtmlAttribute ( nameof ( Action ) , context ) ;
134
136
}
135
137
136
138
if ( Controller != null )
137
139
{
138
- TagHelperOutputHelper . RestoreBoundHtmlAttribute ( nameof ( Controller ) , context , output ) ;
140
+ output . RestoreBoundHtmlAttribute ( nameof ( Controller ) , context ) ;
139
141
}
140
142
141
143
if ( Protocol != null )
142
144
{
143
- TagHelperOutputHelper . RestoreBoundHtmlAttribute ( nameof ( Protocol ) , context , output ) ;
145
+ output . RestoreBoundHtmlAttribute ( nameof ( Protocol ) , context ) ;
144
146
}
145
147
146
148
if ( Host != null )
147
149
{
148
- TagHelperOutputHelper . RestoreBoundHtmlAttribute ( nameof ( Host ) , context , output ) ;
150
+ output . RestoreBoundHtmlAttribute ( nameof ( Host ) , context ) ;
149
151
}
150
152
151
153
if ( Fragment != null )
152
154
{
153
- TagHelperOutputHelper . RestoreBoundHtmlAttribute ( nameof ( Fragment ) , context , output ) ;
155
+ output . RestoreBoundHtmlAttribute ( nameof ( Fragment ) , context ) ;
154
156
}
155
157
156
158
if ( Route != null )
157
159
{
158
- TagHelperOutputHelper . RestoreBoundHtmlAttribute ( nameof ( Route ) , context , output ) ;
160
+ output . RestoreBoundHtmlAttribute ( nameof ( Route ) , context ) ;
159
161
}
160
162
}
161
163
}
0 commit comments