+
+
+
@await Component.InvokeAsync("Tags", 15)
diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs
index fbecf88cde..47ba0034d9 100644
--- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs
@@ -7,6 +7,7 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
+using Microsoft.AspNet.Mvc.ModelBinding;
namespace Microsoft.AspNet.Mvc.Rendering
{
@@ -30,9 +31,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// Initializes a new instance of the class.
///
- public HtmlHelper(IViewEngine viewEngine)
+ public HtmlHelper([NotNull] IViewEngine viewEngine, [NotNull] IModelMetadataProvider metadataProvider)
{
_viewEngine = viewEngine;
+ MetadataProvider = metadataProvider;
// Underscores are fine characters in id's.
IdAttributeDotReplacement = "_";
@@ -75,6 +77,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
}
+ protected IModelMetadataProvider MetadataProvider { get; private set; }
+
///
/// Creates a dictionary of HTML attributes from the input object,
/// translating underscores to dashes.
@@ -125,6 +129,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
return value != null ? WebUtility.HtmlEncode(value.ToString()) : string.Empty;
}
+ ///
+ public string FormatValue(object value, string format)
+ {
+ return ViewDataDictionary.FormatValue(value, format);
+ }
+
public string GenerateIdFromName([NotNull] string name)
{
return TagBuilder.CreateSanitizedId(name, IdAttributeDotReplacement);
@@ -283,7 +293,108 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
}
- public static string GetInputTypeString(InputType inputType)
+ ///
+ public HtmlString TextBox(string name, object value, string format, IDictionary htmlAttributes)
+ {
+ return GenerateTextBox(metadata: null, name: name, value: value, format: format,
+ htmlAttributes: htmlAttributes);
+ }
+
+ protected string EvalString(string key, string format)
+ {
+ return Convert.ToString(ViewData.Eval(key, format), CultureInfo.CurrentCulture);
+ }
+
+ protected object GetModelStateValue(string key, Type destinationType)
+ {
+ ModelState modelState;
+ if (ViewData.ModelState.TryGetValue(key, out modelState) && modelState.Value != null)
+ {
+ return modelState.Value.ConvertTo(destinationType, culture: null);
+ }
+
+ return null;
+ }
+
+ protected IDictionary GetValidationAttributes(string name)
+ {
+ return GetValidationAttributes(name, metadata: null);
+ }
+
+ // Only render attributes if unobtrusive client-side validation is enabled, and then only if we've
+ // never rendered validation for a field with this name in this form. Also, if there's no form context,
+ // then we can't render the attributes (we'd have no