From f0a97772f500d50d64e30c9e209e57502a0dd8c2 Mon Sep 17 00:00:00 2001 From: dougbu Date: Tue, 8 Apr 2014 19:50:06 -0700 Subject: [PATCH] Add remaining HTML input helpers - add `CheckBox[For]()`, `Hidden[For]()`, `Password[For]()`, and `RadioButton[For]()` - also make `FormatValue()` visible to users, as it is in legacy MVC - and spread the boxes out a bit in MyView :smiley_cat: --- samples/MvcSample.Web/HomeController.cs | 1 + samples/MvcSample.Web/Models/User.cs | 1 + .../MvcSample.Web/Views/Shared/MyView.cshtml | 46 ++- .../Rendering/Html/HtmlHelper.cs | 275 +++++++++++++++++- .../Rendering/Html/HtmlHelperOfT.cs | 40 ++- .../Rendering/HtmlHelperInputExtensions.cs | 82 +++++- .../Rendering/IHtmlHelperOfT.cs | 138 +++++++++ 7 files changed, 572 insertions(+), 11 deletions(-) diff --git a/samples/MvcSample.Web/HomeController.cs b/samples/MvcSample.Web/HomeController.cs index 8c3cbfa0ef..e67de46f67 100644 --- a/samples/MvcSample.Web/HomeController.cs +++ b/samples/MvcSample.Web/HomeController.cs @@ -79,6 +79,7 @@ namespace MvcSample.Web Alive = true, Age = 13, GPA = 13.37M, + Password = "Secure string", Dependent = new User() { Name = "Dependents name", diff --git a/samples/MvcSample.Web/Models/User.cs b/samples/MvcSample.Web/Models/User.cs index 825de781e9..10fbf112ad 100644 --- a/samples/MvcSample.Web/Models/User.cs +++ b/samples/MvcSample.Web/Models/User.cs @@ -12,5 +12,6 @@ namespace MvcSample.Web.Models public decimal GPA { get; set; } public User Dependent { get; set; } public bool Alive { get; set; } + public string Password { get; set; } } } \ No newline at end of file diff --git a/samples/MvcSample.Web/Views/Shared/MyView.cshtml b/samples/MvcSample.Web/Views/Shared/MyView.cshtml index 93bbfee5cf..d7f1a43800 100644 --- a/samples/MvcSample.Web/Views/Shared/MyView.cshtml +++ b/samples/MvcSample.Web/Views/Shared/MyView.cshtml @@ -141,6 +141,7 @@
@using (Html.BeginForm(controllerName: "Home", actionName: "Hello", method: FormMethod.Post)) { + @Html.HiddenFor(m => m.Age) + + + + + + + + + + + +
@@ -160,13 +161,44 @@
- + + + @Html.CheckBox("Alive") + or + @Html.RadioButton("Alive", value: false) False + @Html.RadioButton("Alive", value: true) True +
+ + + @Html.CheckBoxFor(m => m.Dependent.Alive) + or + @Html.RadioButtonFor(m => m.Dependent.Alive, value: false) False + @Html.RadioButtonFor(m => m.Dependent.Alive, value: true) True +
+ + + @Html.PasswordFor(m => m.Password, htmlAttributes: new { @class = "form-control" }) +
+
} @{ Html.BeginForm(method: FormMethod.Post, htmlAttributes: new { someAttribute = "some value", }); } + @Html.Hidden("Anon.Id") + + + + @@ -273,7 +313,7 @@
@@ -211,7 +243,15 @@
- + + + @Html.Password("Password", "some string") +
+
-
+
diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelper.cs index 51e75dfa11..8a04566836 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelper.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Globalization; using System.IO; using System.Net; using System.Reflection; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering.Expressions; @@ -50,8 +50,6 @@ namespace Microsoft.AspNet.Mvc.Rendering public string IdAttributeDotReplacement { get; set; } - public HttpContext HttpContext { get; private set; } - public ViewContext ViewContext { get @@ -182,6 +180,11 @@ namespace Microsoft.AspNet.Mvc.Rendering mvcForm.EndForm(); } + public HtmlString CheckBox(string name, bool? isChecked, object htmlAttributes) + { + return GenerateCheckBox(metadata: null, name: name, isChecked: isChecked, htmlAttributes: htmlAttributes); + } + public string Encode(string value) { return (!string.IsNullOrEmpty(value)) ? WebUtility.HtmlEncode(value) : string.Empty; @@ -225,6 +228,12 @@ namespace Microsoft.AspNet.Mvc.Rendering additionalViewData); } + public HtmlString Hidden(string name, object value, object htmlAttributes) + { + return GenerateHidden(metadata: null, name: name, value: value, useViewData: (value == null), + htmlAttributes: htmlAttributes); + } + public virtual HtmlString Name(string name) { var fullName = ViewData.TemplateInfo.GetFullHtmlFieldName(name); @@ -287,6 +296,17 @@ namespace Microsoft.AspNet.Mvc.Rendering await viewEngineResult.View.RenderAsync(newViewContext); } + public HtmlString Password(string name, object value, object htmlAttributes) + { + return GeneratePassword(metadata: null, name: name, value: value, htmlAttributes: htmlAttributes); + } + + public HtmlString RadioButton(string name, object value, bool? isChecked, object htmlAttributes) + { + return GenerateRadioButton(metadata: null, name: name, value: value, isChecked: isChecked, + htmlAttributes: htmlAttributes); + } + public virtual HtmlString ValidationSummary(bool excludePropertyErrors, string message, IDictionary htmlAttributes) { var formContext = ViewContext.ClientValidationEnabled ? ViewContext.FormContext : null; @@ -417,6 +437,16 @@ namespace Microsoft.AspNet.Mvc.Rendering return new MvcForm(ViewContext); } + protected bool EvalBoolean(string key) + { + return Convert.ToBoolean(ViewData.Eval(key), CultureInfo.InvariantCulture); + } + + protected string EvalString(string key) + { + return Convert.ToString(ViewData.Eval(key), CultureInfo.CurrentCulture); + } + protected string EvalString(string key, string format) { return Convert.ToString(ViewData.Eval(key, format), CultureInfo.CurrentCulture); @@ -447,6 +477,54 @@ namespace Microsoft.AspNet.Mvc.Rendering return new Dictionary(); } + protected virtual HtmlString GenerateCheckBox(ModelMetadata metadata, string name, bool? isChecked, + object htmlAttributes) + { + if (metadata != null) + { + // CheckBoxFor() case. That API does not support passing isChecked directly. + Contract.Assert(!isChecked.HasValue); + + if (metadata.Model != null) + { + bool modelChecked; + if (Boolean.TryParse(metadata.Model.ToString(), out modelChecked)) + { + isChecked = modelChecked; + } + } + } + + // Only need a dictionary if htmlAttributes is non-null. TagBuilder.MergeAttributes() is fine with null. + IDictionary htmlAttributeDictionary = null; + if (htmlAttributes != null) + { + htmlAttributeDictionary = htmlAttributes as IDictionary; + if (htmlAttributeDictionary == null) + { + htmlAttributeDictionary = AnonymousObjectToHtmlAttributes(htmlAttributes); + } + } + + var explicitValue = isChecked.HasValue; + if (explicitValue && htmlAttributeDictionary != null) + { + // Explicit value must override dictionary + htmlAttributeDictionary.Remove("checked"); + } + + return GenerateInput(InputType.CheckBox, + metadata, + name, + value: "true", + useViewData: !explicitValue, + isChecked: isChecked ?? false, + setId: true, + isExplicitValue: false, + format: null, + htmlAttributes: htmlAttributeDictionary); + } + /// /// Writes an opening
tag to the response. When the user submits the form, /// the request will be processed by an action method. @@ -496,6 +574,38 @@ namespace Microsoft.AspNet.Mvc.Rendering return theForm; } + protected virtual HtmlString GenerateHidden(ModelMetadata metadata, string name, object value, bool useViewData, + object htmlAttributes) + { + // Only need a dictionary if htmlAttributes is non-null. TagBuilder.MergeAttributes() is fine with null. + IDictionary htmlAttributeDictionary = null; + if (htmlAttributes != null) + { + htmlAttributeDictionary = htmlAttributes as IDictionary; + if (htmlAttributeDictionary == null) + { + htmlAttributeDictionary = AnonymousObjectToHtmlAttributes(htmlAttributes); + } + } + + var byteArrayValue = value as byte[]; + if (byteArrayValue != null) + { + value = Convert.ToBase64String(byteArrayValue); + } + + return GenerateInput(InputType.Hidden, + metadata, + name, + value, + useViewData, + isChecked: false, + setId: true, + isExplicitValue: true, + format: null, + htmlAttributes: htmlAttributeDictionary); + } + protected virtual HtmlString GenerateLink( [NotNull] string linkText, [NotNull] string url, @@ -512,6 +622,99 @@ namespace Microsoft.AspNet.Mvc.Rendering return tagBuilder.ToHtmlString(TagRenderMode.Normal); } + protected virtual HtmlString GeneratePassword(ModelMetadata metadata, string name, object value, + object htmlAttributes) + { + // Only need a dictionary if htmlAttributes is non-null. TagBuilder.MergeAttributes() is fine with null. + IDictionary htmlAttributeDictionary = null; + if (htmlAttributes != null) + { + htmlAttributeDictionary = htmlAttributes as IDictionary; + if (htmlAttributeDictionary == null) + { + htmlAttributeDictionary = AnonymousObjectToHtmlAttributes(htmlAttributes); + } + } + + return GenerateInput(InputType.Password, + metadata, + name, + value, + useViewData: false, + isChecked: false, + setId: true, + isExplicitValue: true, + format: null, + htmlAttributes: htmlAttributeDictionary); + } + + protected virtual HtmlString GenerateRadioButton(ModelMetadata metadata, string name, object value, + bool? isChecked, object htmlAttributes) + { + // Only need a dictionary if htmlAttributes is non-null. TagBuilder.MergeAttributes() is fine with null. + IDictionary htmlAttributeDictionary = null; + if (htmlAttributes != null) + { + htmlAttributeDictionary = htmlAttributes as IDictionary; + if (htmlAttributeDictionary == null) + { + htmlAttributeDictionary = AnonymousObjectToHtmlAttributes(htmlAttributes); + } + } + + if (metadata == null) + { + // RadioButton() case. Do not override checked attribute if isChecked is implicit. + if (!isChecked.HasValue && + (htmlAttributeDictionary == null || !htmlAttributeDictionary.ContainsKey("checked"))) + { + // Note value may be null if isChecked is non-null. + if (value == null) + { + throw new ArgumentNullException("value"); + } + + // isChecked not provided nor found in the given attributes; fall back to view data. + var valueString = Convert.ToString(value, CultureInfo.CurrentCulture); + isChecked = !string.IsNullOrEmpty(name) && + string.Equals(EvalString(name), valueString, StringComparison.OrdinalIgnoreCase); + } + } + else + { + // RadioButtonFor() case. That API does not support passing isChecked directly. + Contract.Assert(!isChecked.HasValue); + if (value == null) + { + // Need a value to determine isChecked. + throw new ArgumentNullException("value"); + } + + var model = metadata.Model; + var valueString = Convert.ToString(value, CultureInfo.CurrentCulture); + isChecked = model != null && + string.Equals(model.ToString(), valueString, StringComparison.OrdinalIgnoreCase); + } + + var explicitValue = isChecked.HasValue; + if (explicitValue && htmlAttributeDictionary != null) + { + // Explicit value must override dictionary + htmlAttributeDictionary.Remove("checked"); + } + + return GenerateInput(InputType.Radio, + metadata, + name, + value, + useViewData: false, + isChecked: isChecked ?? false, + setId: true, + isExplicitValue: true, + format: null, + htmlAttributes: htmlAttributeDictionary); + } + protected virtual HtmlString GenerateTextBox(ModelMetadata metadata, string name, object value, string format, IDictionary htmlAttributes) { @@ -531,8 +734,9 @@ namespace Microsoft.AspNet.Mvc.Rendering object value, bool useViewData, bool isChecked, bool setId, bool isExplicitValue, string format, IDictionary htmlAttributes) { - // Not valid to use TextBoxForModel() in a top-level view; would end up with an unnamed input elements. - // But we support the *ForModel() methods in any lower-level template, once HtmlFieldPrefix is non-empty. + // Not valid to use TextBoxForModel() and so on in a top-level view; would end up with an unnamed input + // elements. But we support the *ForModel() methods in any lower-level template, once HtmlFieldPrefix is + // non-empty. var fullName = ViewData.TemplateInfo.GetFullHtmlFieldName(name); if (string.IsNullOrEmpty(fullName)) { @@ -545,8 +749,51 @@ namespace Microsoft.AspNet.Mvc.Rendering tagBuilder.MergeAttribute("name", fullName, replaceExisting: true); var valueParameter = FormatValue(value, format); + var usedModelState = false; switch (inputType) { + case InputType.CheckBox: + var modelStateWasChecked = GetModelStateValue(fullName, typeof(bool)) as bool?; + if (modelStateWasChecked.HasValue) + { + isChecked = modelStateWasChecked.Value; + usedModelState = true; + } + + goto case InputType.Radio; + + case InputType.Radio: + if (!usedModelState) + { + var modelStateValue = GetModelStateValue(fullName, typeof(string)) as string; + if (modelStateValue != null) + { + isChecked = string.Equals(modelStateValue, valueParameter, StringComparison.Ordinal); + usedModelState = true; + } + } + + if (!usedModelState && useViewData) + { + isChecked = EvalBoolean(fullName); + } + + if (isChecked) + { + tagBuilder.MergeAttribute("checked", "checked"); + } + + tagBuilder.MergeAttribute("value", valueParameter, isExplicitValue); + break; + + case InputType.Password: + if (value != null) + { + tagBuilder.MergeAttribute("value", valueParameter, isExplicitValue); + } + + break; + case InputType.Text: default: var attributeValue = (string)GetModelStateValue(fullName, typeof(string)); @@ -573,6 +820,23 @@ namespace Microsoft.AspNet.Mvc.Rendering tagBuilder.MergeAttributes(GetValidationAttributes(name, metadata)); + if (inputType == InputType.CheckBox) + { + // Generate an additional for checkboxes. This + // addresses scenarios where unchecked checkboxes are not sent in the request. + // Sending a hidden input makes it possible to know that the checkbox was present + // on the page when the request was submitted. + var inputItemBuilder = new StringBuilder(); + inputItemBuilder.Append(tagBuilder.ToString(TagRenderMode.SelfClosing)); + + var hiddenInput = new TagBuilder("input"); + hiddenInput.MergeAttribute("type", GetInputTypeString(InputType.Hidden)); + hiddenInput.MergeAttribute("name", fullName); + hiddenInput.MergeAttribute("value", "false"); + inputItemBuilder.Append(hiddenInput.ToString(TagRenderMode.SelfClosing)); + return new HtmlString(inputItemBuilder.ToString()); + } + return tagBuilder.ToHtmlString(TagRenderMode.SelfClosing); } @@ -611,7 +875,6 @@ namespace Microsoft.AspNet.Mvc.Rendering return new HtmlString(Encode(resolvedValue)); } - private static string GetInputTypeString(InputType inputType) { switch (inputType) diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs index f802c84ca0..c354fd1a3f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs @@ -47,7 +47,16 @@ namespace Microsoft.AspNet.Mvc.Rendering base.Contextualize(viewContext); } + /// + public HtmlString CheckBoxFor([NotNull] Expression> expression, + object htmlAttributes) + { + var metadata = GetModelMetadata(expression); + return GenerateCheckBox(metadata, GetExpressionName(expression), isChecked: null, + htmlAttributes: htmlAttributes); + } + /// public HtmlString DisplayFor([NotNull] Expression> expression, string templateName, string htmlFieldName, @@ -63,6 +72,15 @@ namespace Microsoft.AspNet.Mvc.Rendering additionalViewData); } + /// + public HtmlString HiddenFor([NotNull] Expression> expression, + object htmlAttributes) + { + var metadata = GetModelMetadata(expression); + return GenerateHidden(metadata, GetExpressionName(expression), metadata.Model, useViewData: false, + htmlAttributes: htmlAttributes); + } + /// public HtmlString NameFor([NotNull] Expression> expression) { @@ -70,6 +88,24 @@ namespace Microsoft.AspNet.Mvc.Rendering return Name(expressionName); } + /// + public HtmlString PasswordFor([NotNull] Expression> expression, + object htmlAttributes) + { + var metadata = GetModelMetadata(expression); + return GeneratePassword(metadata, GetExpressionName(expression), value: null, + htmlAttributes: htmlAttributes); + } + + /// + public HtmlString RadioButtonFor([NotNull] Expression> expression, + object value, object htmlAttributes) + { + var metadata = GetModelMetadata(expression); + return GenerateRadioButton(metadata, GetExpressionName(expression), value, isChecked: null, + htmlAttributes: htmlAttributes); + } + /// public HtmlString TextBoxFor([NotNull] Expression> expression, string format, IDictionary htmlAttributes) @@ -95,10 +131,12 @@ namespace Microsoft.AspNet.Mvc.Rendering return metadata; } + /// public HtmlString ValueFor(Expression> expression, string format) { var metadata = GetModelMetadata(expression); - return GenerateValue(ExpressionHelper.GetExpressionText(expression), metadata.Model, format, useViewData: false); + return GenerateValue(ExpressionHelper.GetExpressionText(expression), metadata.Model, format, + useViewData: false); } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperInputExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperInputExtensions.cs index 38fcc1855c..82f52dedfd 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperInputExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperInputExtensions.cs @@ -1,12 +1,92 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; namespace Microsoft.AspNet.Mvc.Rendering { public static class HtmlHelperInputExtensions { + public static HtmlString CheckBox([NotNull] this IHtmlHelper htmlHelper, string name) + { + return htmlHelper.CheckBox(name, isChecked: null, htmlAttributes: null); + } + + public static HtmlString CheckBox([NotNull] this IHtmlHelper htmlHelper, string name, + bool isChecked) + { + return htmlHelper.CheckBox(name, isChecked, htmlAttributes: null); + } + + public static HtmlString CheckBox([NotNull] this IHtmlHelper htmlHelper, string name, + object htmlAttributes) + { + return htmlHelper.CheckBox(name, isChecked: null, htmlAttributes: htmlAttributes); + } + + public static HtmlString CheckBoxFor([NotNull] this IHtmlHelper htmlHelper, + [NotNull] Expression> expression) + { + return htmlHelper.CheckBoxFor(expression, htmlAttributes: null); + } + + public static HtmlString Hidden([NotNull] this IHtmlHelper htmlHelper, string name) + { + return htmlHelper.Hidden(name, value: null, htmlAttributes: null); + } + + public static HtmlString Hidden([NotNull] this IHtmlHelper htmlHelper, string name, + object value) + { + return htmlHelper.Hidden(name, value, htmlAttributes: null); + } + + public static HtmlString HiddenFor([NotNull] this IHtmlHelper htmlHelper, + [NotNull] Expression> expression) + { + return htmlHelper.HiddenFor(expression, htmlAttributes: null); + } + + public static HtmlString Password([NotNull] this IHtmlHelper htmlHelper, string name) + { + return htmlHelper.Password(name, value: null, htmlAttributes: null); + } + + public static HtmlString Password([NotNull] this IHtmlHelper htmlHelper, string name, + object value) + { + return htmlHelper.Password(name, value, htmlAttributes: null); + } + + public static HtmlString PasswordFor([NotNull] this IHtmlHelper htmlHelper, + [NotNull] Expression> expression) + { + return htmlHelper.PasswordFor(expression, htmlAttributes: null); + } + + public static HtmlString RadioButton([NotNull] this IHtmlHelper htmlHelper, string name, + object value) + { + return htmlHelper.RadioButton(name, value, isChecked: null, htmlAttributes: null); + } + + public static HtmlString RadioButton([NotNull] this IHtmlHelper htmlHelper, string name, + object value, object htmlAttributes) + { + return htmlHelper.RadioButton(name, value, isChecked: null, htmlAttributes: htmlAttributes); + } + + public static HtmlString RadioButton([NotNull] this IHtmlHelper htmlHelper, string name, + object value, bool isChecked) + { + return htmlHelper.RadioButton(name, value, isChecked, htmlAttributes: null); + } + + public static HtmlString RadioButtonFor([NotNull] this IHtmlHelper htmlHelper, + [NotNull] Expression> expression, object value) + { + return htmlHelper.RadioButtonFor(expression, value, htmlAttributes: null); + } + public static HtmlString TextBox([NotNull] this IHtmlHelper htmlHelper, string name) { return TextBox(htmlHelper, name, value: null); diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelperOfT.cs index 09b7953b15..a758809f80 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelperOfT.cs @@ -86,6 +86,37 @@ namespace Microsoft.AspNet.Mvc.Rendering ///
void EndForm(); + /// + /// Render an input element of type "checkbox" with value "true" and an input element of type "hidden" with + /// value "false". + /// + /// + /// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data + /// only if value is not in submitted data and is null. + /// + /// + /// If true, checkbox is initially checked. Ignore if named value is found in submitted data. Finally + /// fall back to an existing "checked" value in . + /// + /// An object that contains the HTML attributes to set for the element. + /// Alternatively, an instance containing the HTML attributes. + /// + /// New containing the rendered HTML. + HtmlString CheckBox(string name, bool? isChecked, object htmlAttributes); + + /// + /// Render an input element of type "checkbox" with value "true" and an input element of type "hidden" with + /// value "false". + /// + /// + /// An expression that identifies the object that contains the properties to render. + /// + /// An object that contains the HTML attributes to set for the element. + /// Alternatively, an instance containing the HTML attributes. + /// + /// New containing the rendered HTML. + HtmlString CheckBoxFor([NotNull] Expression> expression, object htmlAttributes); + /// /// Returns HTML markup for each property in the object that is represented by the expression, using the specified /// template, HTML field ID, and additional view data. @@ -158,6 +189,14 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The HTML-encoded string. string Encode(string value); + /// + /// Formats the value. + /// + /// The value. + /// The format string. + /// The formatted value. + string FormatValue(object value, string format); + /// /// Creates an HTML element ID using the specified element name. /// @@ -165,6 +204,35 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The ID of the HTML element. string GenerateIdFromName(string name); + /// + /// Render an input element of type "hidden". + /// + /// + /// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data + /// only if value is not in submitted data and is null. + /// + /// + /// If non-null, value to include in the element. Ignore if named value is found in submitted data. + /// + /// An object that contains the HTML attributes to set for the element. + /// Alternatively, an instance containing the HTML attributes. + /// + /// New containing the rendered HTML. + HtmlString Hidden(string name, object value, object htmlAttributes); + + /// + /// Render an input element of type "hidden". + /// + /// + /// An expression that identifies the object that contains the properties to render. + /// + /// An object that contains the HTML attributes to set for the element. + /// Alternatively, an instance containing the HTML attributes. + /// + /// New containing the rendered HTML. + HtmlString HiddenFor([NotNull] Expression> expression, + object htmlAttributes); + /// /// Gets the full HTML field name for the given expression . /// @@ -180,6 +248,76 @@ namespace Microsoft.AspNet.Mvc.Rendering /// An that represents HTML markup. HtmlString NameFor([NotNull] Expression> expression); + /// + /// Render an input element of type "password". + /// + /// + /// Rendered element's name. Also use this name to find value in view data. Use view data + /// only if value is not in submitted data and is null. + /// + /// + /// If non-null, value to include in the element. + /// + /// An object that contains the HTML attributes to set for the element. + /// Alternatively, an instance containing the HTML attributes. + /// + /// New containing the rendered HTML. + HtmlString Password(string name, object value, object htmlAttributes); + + /// + /// Render an input element of type "password". + /// + /// + /// An expression that identifies the object that contains the properties to render. + /// + /// An object that contains the HTML attributes to set for the element. + /// Alternatively, an instance containing the HTML attributes. + /// + /// New containing the rendered HTML. + HtmlString PasswordFor([NotNull] Expression> expression, + object htmlAttributes); + + /// + /// Render an input element of type "radio". + /// + /// + /// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data + /// only if value is not in submitted data and is null. + /// + /// + /// If non-null, value to include in the element. May be null only if + /// is also null. Also compared to value in submitted data or view data to + /// determine if that parameter is null. Ignore if named value is found in + /// submitted data. + /// + /// + /// If true, radio button is initially selected. Ignore if named value is found in submitted data. Fall + /// back to comparing with view data if this parameter is null. Finally + /// fall back to an existing "checked" value in . + /// + /// An object that contains the HTML attributes to set for the element. + /// Alternatively, an instance containing the HTML attributes. + /// + /// New containing the rendered HTML. + HtmlString RadioButton(string name, object value, bool? isChecked, object htmlAttributes); + + /// + /// Render an input element of type "radio". + /// + /// + /// An expression that identifies the object that contains the properties to render. + /// + /// + /// If non-null, value to compare with current expression value to determine whether radio button is + /// checked. + /// + /// An object that contains the HTML attributes to set for the element. + /// Alternatively, an instance containing the HTML attributes. + /// + /// New containing the rendered HTML. + HtmlString RadioButtonFor([NotNull] Expression> expression, object value, + object htmlAttributes); + /// /// Wraps HTML markup in an , which will enable HTML markup to be /// rendered to the output without getting HTML encoded.