;
- if (itemsList == null)
- {
- itemsList = selectList.ToList();
- }
-
// Group items in the SelectList if requested.
// The worst case complexity of this algorithm is O(number of groups*n).
// If there aren't any groups, it is O(n) where n is number of items in the list.
diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs
index f1e9eaf475..666b6bef78 100644
--- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs
+++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs
@@ -769,24 +769,21 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
isChecked,
htmlAttributes);
- var hiddenForCheckboxTag = _htmlGenerator.GenerateHiddenForCheckbox(ViewContext, modelExplorer, expression);
- if (checkbox == null || hiddenForCheckboxTag == null)
+ var hiddenForCheckbox = _htmlGenerator.GenerateHiddenForCheckbox(ViewContext, modelExplorer, expression);
+ if (checkbox == null || hiddenForCheckbox == null)
{
return HtmlString.Empty;
}
- var checkboxContent = new HtmlContentBuilder().AppendHtml(checkbox);
-
if (ViewContext.FormContext.CanRenderAtEndOfForm)
{
- ViewContext.FormContext.EndOfFormContent.Add(hiddenForCheckboxTag);
- }
- else
- {
- checkboxContent.AppendHtml(hiddenForCheckboxTag);
+ ViewContext.FormContext.EndOfFormContent.Add(hiddenForCheckbox);
+ return checkbox;
}
- return checkboxContent;
+ return new HtmlContentBuilder(capacity: 2)
+ .AppendHtml(checkbox)
+ .AppendHtml(hiddenForCheckbox);
}
protected virtual string GenerateDisplayName(ModelExplorer modelExplorer, string expression)
diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Rendering/TagBuilderTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Rendering/TagBuilderTest.cs
index 87d0f7ff0e..55a37da7e4 100644
--- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Rendering/TagBuilderTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Rendering/TagBuilderTest.cs
@@ -117,7 +117,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Rendering
[InlineData("attribute", "value", "")]
[InlineData("attribute", null, "")]
[InlineData("attribute", "", "")]
- public void WriteTo_WriteEmptyAttribute_WhenValueIsNullOrEmpty(string attributeKey, string attributeValue, string expectedOutput)
+ public void WriteTo_WriteEmptyAttribute_WhenValueIsNullOrEmpty(
+ string attributeKey,
+ string attributeValue,
+ string expectedOutput)
{
// Arrange
var tagBuilder = new TagBuilder("p");
@@ -149,6 +152,22 @@ namespace Microsoft.AspNetCore.Mvc.Core.Rendering
// Assert
Assert.Equal("HelloHtmlEncode[[, World!]]
", writer.ToString());
}
+
+ Assert.True(tagBuilder.HasInnerHtml);
+ }
+
+ [Fact]
+ public void ReadingInnerHtml_LeavesHasInnerHtmlFalse()
+ {
+ // Arrange
+ var tagBuilder = new TagBuilder("p");
+
+ // Act
+ var innerHtml = tagBuilder.InnerHtml;
+
+ // Assert
+ Assert.False(tagBuilder.HasInnerHtml);
+ Assert.NotNull(innerHtml);
}
}
}
\ No newline at end of file