diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/CurrentValues.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/CurrentValues.cs new file mode 100644 index 0000000000..cf0389f423 --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/CurrentValues.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Diagnostics; + +namespace Microsoft.AspNet.Mvc.TagHelpers.Internal +{ + public class CurrentValues + { + public CurrentValues(ICollection values) + { + Debug.Assert(values != null); + Values = values; + } + + public ICollection Values { get; } + + public ICollection ValuesAndEncodedValues { get; set; } + } +} diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs index b897eb580e..1603bad918 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; +using Microsoft.AspNet.Mvc.TagHelpers.Internal; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.TagHelpers; @@ -55,8 +56,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// /// /// Does nothing unless contains a - /// entry and that entry is a non-empty - /// instance. Also does nothing if the associated <option> is already + /// entry and that entry is a non-null + /// instance. Also does nothing if the associated <option> is already /// selected. /// public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) @@ -85,32 +86,43 @@ namespace Microsoft.AspNet.Mvc.TagHelpers context.Items.TryGetValue(typeof(SelectTagHelper), out formDataEntry); // ... And did the SelectTagHelper determine any selected values? - var selectedValues = formDataEntry as ICollection; - if (selectedValues != null && selectedValues.Count != 0) + var currentValues = formDataEntry as CurrentValues; + if (currentValues?.Values != null && currentValues.Values.Count != 0) { - // Encode all selected values for comparison with element content. - var encodedValues = new HashSet(StringComparer.OrdinalIgnoreCase); - foreach (var selectedValue in selectedValues) - { - encodedValues.Add(Generator.Encode(selectedValue)); - } - - // Select this