(StringComparer.OrdinalIgnoreCase);
-
- // Perf: Avoid allocating enumerator
- // Construct attributes correctly (first attribute wins).
- for (var i = 0; i < output.Attributes.Count; i++)
+ // hiddenForCheckboxTag always rendered after the returned element
+ var hiddenForCheckboxTag = Generator.GenerateHiddenForCheckbox(ViewContext, modelExplorer, For.Name);
+ if (hiddenForCheckboxTag != null)
{
- var attribute = output.Attributes[i];
- if (!htmlAttributes.ContainsKey(attribute.Name))
+ var renderingMode =
+ output.TagMode == TagMode.SelfClosing ? TagRenderMode.SelfClosing : TagRenderMode.StartTag;
+ hiddenForCheckboxTag.TagRenderMode = renderingMode;
+
+ if (ViewContext.FormContext.CanRenderAtEndOfForm)
{
- htmlAttributes.Add(attribute.Name, attribute.Value);
+ ViewContext.FormContext.EndOfFormContent.Add(hiddenForCheckboxTag);
+ }
+ else
+ {
+ output.PostElement.AppendHtml(hiddenForCheckboxTag);
}
}
- var checkBoxTag = Generator.GenerateCheckBox(
+ return Generator.GenerateCheckBox(
ViewContext,
modelExplorer,
For.Name,
isChecked: null,
- htmlAttributes: htmlAttributes);
- if (checkBoxTag != null)
- {
- // Do not generate current element's attributes or tags. Instead put both and
- // into the output's Content.
- output.Attributes.Clear();
- output.TagName = null;
-
- var renderingMode =
- output.TagMode == TagMode.SelfClosing ? TagRenderMode.SelfClosing : TagRenderMode.StartTag;
- checkBoxTag.TagRenderMode = renderingMode;
- output.Content.AppendHtml(checkBoxTag);
-
- var hiddenForCheckboxTag = Generator.GenerateHiddenForCheckbox(ViewContext, modelExplorer, For.Name);
- if (hiddenForCheckboxTag != null)
- {
- hiddenForCheckboxTag.TagRenderMode = renderingMode;
-
- if (ViewContext.FormContext.CanRenderAtEndOfForm)
- {
- ViewContext.FormContext.EndOfFormContent.Add(hiddenForCheckboxTag);
- }
- else
- {
- output.Content.AppendHtml(hiddenForCheckboxTag);
- }
- }
- }
+ htmlAttributes: null);
}
private TagBuilder GenerateRadio(ModelExplorer modelExplorer)
diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Order.Encoded.html b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Order.Encoded.html
index 97428777dc..aee1e808a2 100644
--- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Order.Encoded.html
+++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Order.Encoded.html
@@ -65,7 +65,7 @@
-
+
diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Order.html b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Order.html
index 2d40eeca1f..54a6af28f8 100644
--- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Order.html
+++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Order.html
@@ -65,7 +65,7 @@
-
+
diff --git a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/InputTagHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/InputTagHelperTest.cs
index a92a669983..e9799a4cbb 100644
--- a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/InputTagHelperTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/InputTagHelperTest.cs
@@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
{ "hello", "world" },
{ "hello", "world2" }
},
- "hello=\"HtmlEncode[[world]]\""
+ "hello=\"HtmlEncode[[world]]\" hello=\"HtmlEncode[[world2]]\""
},
{
new TagHelperAttributeList
@@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
{ "hello", "world2" },
{ "hello", "world3" }
},
- "hello=\"HtmlEncode[[world]]\""
+ "hello=\"HtmlEncode[[world]]\" hello=\"HtmlEncode[[world2]]\" hello=\"HtmlEncode[[world3]]\""
},
{
new TagHelperAttributeList
@@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
{ "HelLO", "world" },
{ "HELLO", "world2" }
},
- "HelLO=\"HtmlEncode[[world]]\""
+ "HelLO=\"HtmlEncode[[world]]\" HELLO=\"HtmlEncode[[world2]]\""
},
{
new TagHelperAttributeList
@@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
{ "HELLO", "world2" },
{ "hello", "world3" }
},
- "Hello=\"HtmlEncode[[world]]\""
+ "Hello=\"HtmlEncode[[world]]\" HELLO=\"HtmlEncode[[world2]]\" hello=\"HtmlEncode[[world3]]\""
},
{
new TagHelperAttributeList
@@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
{ "HeLlO", "world" },
{ "hello", "world2" }
},
- "HeLlO=\"HtmlEncode[[world]]\""
+ "HeLlO=\"HtmlEncode[[world]]\" hello=\"HtmlEncode[[world2]]\""
},
};
}
@@ -76,15 +76,14 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
[Theory]
[MemberData(nameof(MultiAttributeCheckBoxData))]
- public async Task CheckBoxHandlesMultipleAttributesSameNameCorrectly(
+ public async Task CheckBoxHandlesMultipleAttributesSameNameArePreserved(
TagHelperAttributeList outputAttributes,
string expectedAttributeString)
{
// Arrange
var originalContent = "original content";
- var originalTagName = "not-input";
- var expectedContent = $"{originalContent}" +
+ var expectedContent = $"" +
"";
var context = new TagHelperContext(
@@ -94,12 +93,13 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
items: new Dictionary