diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs
index eeaaa58316..1864c457b7 100644
--- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs
+++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs
@@ -98,8 +98,8 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
/// attribute to that formatted .
///
///
- /// Used only the calculated "type" attribute is "text" (the most common value) e.g.
- /// is "String". That is, is used when calling
+ /// Not used if the provided (see ) or calculated "type" attribute value is
+ /// checkbox, password, or radio. That is, is used when calling
/// .
///
[HtmlAttributeName(FormatAttributeName)]
@@ -110,8 +110,9 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
///
///
/// Passed through to the generated HTML in all cases. Also used to determine the
- /// helper to call and the default value (when calling
- /// ).
+ /// helper to call and the default value. A default is not calculated
+ /// if the provided (see ) or calculated "type" attribute value is checkbox,
+ /// hidden, password, or radio.
///
[HtmlAttributeName("type")]
public string InputTypeName { get; set; }
@@ -358,6 +359,8 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
htmlAttributes: htmlAttributes);
}
+ // Imitate Generator.GenerateHidden() using Generator.GenerateTextBox(). This adds support for asp-format that
+ // is not available in Generator.GenerateHidden().
private TagBuilder GenerateHidden(ModelExplorer modelExplorer)
{
var value = For.Model;
@@ -367,6 +370,9 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
value = Convert.ToBase64String(byteArrayValue);
}
+ // In DefaultHtmlGenerator(), GenerateTextBox() calls GenerateInput() _almost_ identically to how
+ // GenerateHidden() does and the main switch inside GenerateInput() handles InputType.Text and
+ // InputType.Hidden identically. No behavior differences at all when a type HTML attribute already exists.
var htmlAttributes = new Dictionary
{
{ "type", "hidden" }
diff --git a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/InputTagHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/InputTagHelperTest.cs
index cabe292766..be2ee35a4f 100644
--- a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/InputTagHelperTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/InputTagHelperTest.cs
@@ -246,6 +246,75 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
Assert.Equal(expectedTagName, output.TagName);
}
+ [Theory]
+ [InlineData(null, "datetime")]
+ [InlineData("hidden", "hidden")]
+ public void Process_GeneratesFormattedOutput(string specifiedType, string expectedType)
+ {
+ // Arrange
+ var expectedAttributes = new TagHelperAttributeList
+ {
+ { "type", expectedType },
+ { "id", "DateTimeOffset" },
+ { "name", "DateTimeOffset" },
+ { "valid", "from validation attributes" },
+ { "value", "datetime: 2011-08-31T05:30:45.0000000+03:00" },
+ };
+ var expectedTagName = "not-input";
+ var container = new Model
+ {
+ DateTimeOffset = new DateTimeOffset(2011, 8, 31, hour: 5, minute: 30, second: 45, offset: TimeSpan.FromHours(3))
+ };
+
+ var allAttributes = new TagHelperAttributeList
+ {
+ { "type", specifiedType },
+ };
+ var context = new TagHelperContext(
+ allAttributes: allAttributes,
+ items: new Dictionary