From 4123d83d26e528fe09c870cc92d4aecf0e80d3f7 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Fri, 5 Feb 2016 15:11:51 -0800 Subject: [PATCH] [Fixes #4047] SelectTagHelpers: asp-items shouldn't require/depend on asp-for. --- .../SelectTagHelper.cs | 21 +++++- .../ViewFeatures/DefaultHtmlGenerator.cs | 3 +- .../ViewFeatures/IHtmlGenerator.cs | 13 ++++ .../SelectTagHelperTest.cs | 74 +++++++++++++++++++ 4 files changed, 106 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/SelectTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/SelectTagHelper.cs index 92cab6b0e3..f650216b72 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/SelectTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/SelectTagHelper.cs @@ -15,9 +15,11 @@ using Microsoft.AspNetCore.Razor.TagHelpers; namespace Microsoft.AspNetCore.Mvc.TagHelpers { /// - /// implementation targeting <select> elements with an asp-for attribute. + /// implementation targeting <select> elements with asp-for and/or + /// asp-items attribute(s). /// [HtmlTargetElement("select", Attributes = ForAttributeName)] + [HtmlTargetElement("select", Attributes = ItemsAttributeName)] public class SelectTagHelper : TagHelper { private const string ForAttributeName = "asp-for"; @@ -70,6 +72,13 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers throw new ArgumentNullException(nameof(context)); } + if (For == null) + { + // Informs contained elements that they're running within a targeted