Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 9626739

Browse files
author
NTaylorMullen
committed
Addressed code review comments and modified to use latest bits.
1 parent 31cb253 commit 9626739

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Linq;
67
using Microsoft.AspNet.Mvc.Rendering;
7-
using Microsoft.AspNet.Mvc.TagHelpers.Internal;
88
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
99

1010
namespace Microsoft.AspNet.Mvc.TagHelpers
@@ -17,9 +17,6 @@ public class AnchorTagHelper : TagHelper
1717
{
1818
private const string RouteAttributePrefix = "route-";
1919

20-
[Activate]
21-
private ViewContext ViewContext { get; set; }
22-
2320
[Activate]
2421
private IHtmlGenerator Generator { get; set; }
2522

@@ -82,13 +79,18 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
8279
{
8380
TagBuilder tagBuilder;
8481

85-
var prefixedValues = TagHelperOutputHelper.PullPrefixedAttributes(RouteAttributePrefix, output);
82+
var prefixedValues = output.PullPrefixedAttributes(RouteAttributePrefix);
83+
84+
Dictionary<string, object> routeValues = null;
8685

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+
}
9294

9395
if (Route == null)
9496
{
@@ -122,40 +124,40 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
122124
htmlAttributes: null);
123125
}
124126

125-
TagHelperOutputHelper.MergeAttributes(tagBuilder, output);
127+
output.MergeAttributes(tagBuilder);
126128
}
127129
}
128130

129131
private void RestoreBoundHtmlAttributes(TagHelperContext context, TagHelperOutput output)
130132
{
131133
if (Action != null)
132134
{
133-
TagHelperOutputHelper.RestoreBoundHtmlAttribute(nameof(Action), context, output);
135+
output.RestoreBoundHtmlAttribute(nameof(Action), context);
134136
}
135137

136138
if (Controller != null)
137139
{
138-
TagHelperOutputHelper.RestoreBoundHtmlAttribute(nameof(Controller), context, output);
140+
output.RestoreBoundHtmlAttribute(nameof(Controller), context);
139141
}
140142

141143
if (Protocol != null)
142144
{
143-
TagHelperOutputHelper.RestoreBoundHtmlAttribute(nameof(Protocol), context, output);
145+
output.RestoreBoundHtmlAttribute(nameof(Protocol), context);
144146
}
145147

146148
if (Host != null)
147149
{
148-
TagHelperOutputHelper.RestoreBoundHtmlAttribute(nameof(Host), context, output);
150+
output.RestoreBoundHtmlAttribute(nameof(Host), context);
149151
}
150152

151153
if (Fragment != null)
152154
{
153-
TagHelperOutputHelper.RestoreBoundHtmlAttribute(nameof(Fragment), context, output);
155+
output.RestoreBoundHtmlAttribute(nameof(Fragment), context);
154156
}
155157

156158
if (Route != null)
157159
{
158-
TagHelperOutputHelper.RestoreBoundHtmlAttribute(nameof(Route), context, output);
160+
output.RestoreBoundHtmlAttribute(nameof(Route), context);
159161
}
160162
}
161163
}

0 commit comments

Comments
 (0)