selectList, object htmlAttributes)
@@ -1063,12 +1071,12 @@ Environment.NewLine;
public HtmlString Password(string name, object value, object htmlAttributes)
{
- return new HtmlString("__Password__");
+ return HelperName("__Password__", htmlAttributes);
}
public HtmlString RadioButton(string name, object value, bool? isChecked, object htmlAttributes)
{
- return new HtmlString("__RadioButton__");
+ return HelperName("__RadioButton__", htmlAttributes);
}
public HtmlString Raw(object value)
@@ -1100,17 +1108,17 @@ Environment.NewLine;
public HtmlString TextArea(string name, string value, int rows, int columns, object htmlAttributes)
{
- return new HtmlString("__TextArea__");
+ return HelperName("__TextArea__", htmlAttributes);
}
public HtmlString TextBox(string name, object value, string format, object htmlAttributes)
{
- return new HtmlString("__TextBox__");
+ return HelperName("__TextBox__", htmlAttributes);
}
public HtmlString ValidationMessage(string modelName, string message, object htmlAttributes, string tag)
{
- return new HtmlString("__ValidationMessage__");
+ return HelperName("__ValidationMessage__", htmlAttributes);
}
public HtmlString ValidationSummary(
@@ -1126,6 +1134,16 @@ Environment.NewLine;
{
throw new NotImplementedException();
}
+
+ private HtmlString HelperName(string name, object htmlAttributes)
+ {
+ var htmlAttributesDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
+ var htmlAttributesString =
+ string.Join(" ", htmlAttributesDictionary.Select(entry => $"{ entry.Key }='{ entry.Value }'"));
+ var helperName = $"{ name } { htmlAttributesString }";
+
+ return new HtmlString(helperName.TrimEnd());
+ }
}
}
}
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/TagHelpersWebSite.Employee.Create.Invalid.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/TagHelpersWebSite.Employee.Create.Invalid.html
index 44f32743b6..99144d46c1 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/TagHelpersWebSite.Employee.Create.Invalid.html
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/TagHelpersWebSite.Employee.Create.Invalid.html
@@ -55,7 +55,7 @@
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs
index 806abfc296..087865ee98 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
@@ -378,8 +379,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var htmlGenerator = new Mock(MockBehavior.Strict);
var tagHelper = GetTagHelper(
- htmlGenerator.Object,
- model,
+ htmlGenerator.Object,
+ model,
nameof(Model.Text),
metadataProvider: metadataProvider);
tagHelper.InputTypeName = inputTypeName;
@@ -579,8 +580,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var htmlGenerator = new Mock(MockBehavior.Strict);
var tagHelper = GetTagHelper(
- htmlGenerator.Object,
- model,
+ htmlGenerator.Object,
+ model,
nameof(Model.Text),
metadataProvider: metadataProvider);
tagHelper.InputTypeName = inputTypeName;
@@ -617,9 +618,165 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal(expectedTagName, output.TagName);
}
+ [Theory]
+ [InlineData(null, null, "text")]
+ [InlineData("Byte", null, "number")]
+ [InlineData("custom-datatype", null, "text")]
+ [InlineData("Custom-Datatype", null, "text")]
+ [InlineData("date", null, "date")] // No date/time special cases since ModelType is string.
+ [InlineData("datetime", null, "datetime")]
+ [InlineData("datetime-local", null, "datetime-local")]
+ [InlineData("DATETIME-local", null, "datetime-local")]
+ [InlineData("Decimal", "{0:0.00}", "text")]
+ [InlineData("Double", null, "number")]
+ [InlineData("Int16", null, "number")]
+ [InlineData("Int32", null, "number")]
+ [InlineData("int32", null, "number")]
+ [InlineData("Int64", null, "number")]
+ [InlineData("SByte", null, "number")]
+ [InlineData("Single", null, "number")]
+ [InlineData("SINGLE", null, "number")]
+ [InlineData("string", null, "text")]
+ [InlineData("STRING", null, "text")]
+ [InlineData("text", null, "text")]
+ [InlineData("TEXT", null, "text")]
+ [InlineData("time", null, "time")]
+ [InlineData("UInt16", null, "number")]
+ [InlineData("uint16", null, "number")]
+ [InlineData("UInt32", null, "number")]
+ [InlineData("UInt64", null, "number")]
+ public async Task ProcessAsync_CallsGenerateTextBox_AddsExpectedAttributes(
+ string dataTypeName,
+ string expectedFormat,
+ string expectedType)
+ {
+ // Arrange
+ var expectedAttributes = new Dictionary
+ {
+ { "type", expectedType }, // Calculated; not passed to HtmlGenerator.
+ };
+ var expectedTagName = "not-input";
+
+ var context = new TagHelperContext(
+ allAttributes: new Dictionary(),
+ items: new Dictionary