diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Properties/Resources.Designer.cs index 183d549f26..c46e3e4940 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Properties/Resources.Designer.cs @@ -122,22 +122,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers return string.Format(CultureInfo.CurrentCulture, GetString("SelectTagHelper_CannotDetermineContentWhenOnlyItemsSpecified"), p0, p1, p2); } - /// - /// Cannot parse '{1}' value '{2}' for {0}. Acceptable values are '{3}', '{4}' and '{5}'. - /// - internal static string TagHelpers_InvalidValue_ThreeAcceptableValues - { - get { return GetString("TagHelpers_InvalidValue_ThreeAcceptableValues"); } - } - - /// - /// Cannot parse '{1}' value '{2}' for {0}. Acceptable values are '{3}', '{4}' and '{5}'. - /// - internal static string FormatTagHelpers_InvalidValue_ThreeAcceptableValues(object p0, object p1, object p2, object p3, object p4, object p5) - { - return string.Format(CultureInfo.CurrentCulture, GetString("TagHelpers_InvalidValue_ThreeAcceptableValues"), p0, p1, p2, p3, p4, p5); - } - /// /// The {2} was unable to provide metadata about '{1}' expression value '{3}' for {0}. /// diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Resources.resx b/src/Microsoft.AspNet.Mvc.TagHelpers/Resources.resx index 43bda290f1..ce38a162fc 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Resources.resx +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Resources.resx @@ -138,9 +138,6 @@ Cannot determine body for {0}. '{2}' must be null if '{1}' is null. - - Cannot parse '{1}' value '{2}' for {0}. Acceptable values are '{3}', '{4}' and '{5}'. - The {2} was unable to provide metadata about '{1}' expression value '{3}' for {0}. diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/SelectTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/SelectTagHelper.cs index 9a2ebd45c2..e28fb59aa1 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/SelectTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/SelectTagHelper.cs @@ -8,7 +8,6 @@ using System.Linq; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Razor.Runtime.TagHelpers; -using Microsoft.AspNet.Razor.TagHelpers; namespace Microsoft.AspNet.Mvc.TagHelpers { @@ -44,16 +43,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers [HtmlAttributeName(ForAttributeName)] public ModelExpression For { get; set; } - /// - /// Specifies that multiple options can be selected at once. - /// - /// - /// Passed through to the generated HTML if value is multiple. Converted to multiple or absent if - /// value is true or false. Other values are not acceptable. Also used to determine the correct - /// "selected" attributes for generated <option> elements. - /// - public string Multiple { get; set; } - /// /// A collection of objects used to populate the <select> element with /// <optgroup> and <option> elements. @@ -79,12 +68,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers ItemsAttributeName); throw new InvalidOperationException(message); } - - // Pass through attribute that is also a well-known HTML attribute. - if (!string.IsNullOrEmpty(Multiple)) - { - output.CopyHtmlAttribute(nameof(Multiple), context); - } } else { @@ -100,33 +83,12 @@ namespace Microsoft.AspNet.Mvc.TagHelpers For.Name)); } - bool allowMultiple; - if (string.IsNullOrEmpty(Multiple)) - { - // Base allowMultiple on the instance or declared type of the expression. - var realModelType = For.Metadata.RealModelType; - allowMultiple = + // Base allowMultiple on the instance or declared type of the expression to avoid a + // "SelectExpressionNotEnumerable" InvalidOperationException during generation. + // Metadata.IsCollectionType() is similar but does not take runtime type into account. + var realModelType = For.Metadata.RealModelType; + var allowMultiple = typeof(string) != realModelType && typeof(IEnumerable).IsAssignableFrom(realModelType); - } - else if (string.Equals(Multiple, "multiple", StringComparison.OrdinalIgnoreCase)) - { - allowMultiple = true; - - // Copy exact attribute name and value the user entered. Must be done prior to any copying from a - // TagBuilder. Not done in next case because "true" and "false" aren't valid for the HTML 5 - // attribute. - output.CopyHtmlAttribute(nameof(Multiple), context); - } - else if (!bool.TryParse(Multiple.ToLowerInvariant(), out allowMultiple)) - { - throw new InvalidOperationException(Resources.FormatTagHelpers_InvalidValue_ThreeAcceptableValues( - ". Acceptable values are 'false', 'true' and 'multiple'."; - - var tagHelperContext = new TagHelperContext( - contextAttributes, - uniqueId: "test", - getChildContentAsync: () => Task.FromResult("Something")); - var output = new TagHelperOutput(expectedTagName, originalAttributes); - - var metadataProvider = new EmptyModelMetadataProvider(); - string model = null; - var metadata = metadataProvider.GetMetadataForType(() => model, typeof(string)); - var modelExpression = new ModelExpression("Property1", metadata); - - var tagHelper = new SelectTagHelper - { - For = modelExpression, - Multiple = multiple, - }; - - // Act & Assert - var exception = await Assert.ThrowsAsync( - () => tagHelper.ProcessAsync(tagHelperContext, output)); - Assert.Equal(expectedMessage, exception.Message); - } - public class NameAndId { public NameAndId(string name, string id)