InputExtensions Class
Represents support for HTML input controls in an application.
Inheritance Hierarchy
System.Object
System.Web.Mvc.Html.InputExtensions
Namespace: System.Web.Mvc.Html
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public NotInheritable Class InputExtensions
public static class InputExtensions
[ExtensionAttribute]
public ref class InputExtensions abstract sealed
Methods
Name | Description | |
---|---|---|
CheckBox(HtmlHelper, String) | Returns a check box input element by using the specified HTML helper and the name of the form field. | |
CheckBox(HtmlHelper, String, Boolean) | Returns a check box input element by using the specified HTML helper, the name of the form field, and a value to indicate whether the check box is selected. | |
CheckBox(HtmlHelper, String, IDictionary<String, Object>) | Returns a check box input element by using the specified HTML helper, the name of the form field, and the HTML attributes. | |
CheckBox(HtmlHelper, String, Object) | Returns a check box input element by using the specified HTML helper, the name of the form field, and the HTML attributes. | |
CheckBox(HtmlHelper, String, Boolean, IDictionary<String, Object>) | Returns a check box input element by using the specified HTML helper, the name of the form field, a value to indicate whether the check box is selected, and the HTML attributes. | |
CheckBox(HtmlHelper, String, Boolean, Object) | Returns a check box input element by using the specified HTML helper, the name of the form field, a value that indicates whether the check box is selected, and the HTML attributes. | |
CheckBoxFor<TModel>(HtmlHelper<TModel>, Expression<Func<TModel, Boolean>>) | Returns a check box input element for each property in the object that is represented by the specified expression. | |
CheckBoxFor<TModel>(HtmlHelper<TModel>, Expression<Func<TModel, Boolean>>, IDictionary<String, Object>) | Returns a check box input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
CheckBoxFor<TModel>(HtmlHelper<TModel>, Expression<Func<TModel, Boolean>>, Object) | Returns a check box input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
Hidden(HtmlHelper, String) | Returns a hidden input element by using the specified HTML helper and the name of the form field. | |
Hidden(HtmlHelper, String, Object) | Returns a hidden input element by using the specified HTML helper, the name of the form field, and the value. | |
Hidden(HtmlHelper, String, Object, IDictionary<String, Object>) | Returns a hidden input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. | |
Hidden(HtmlHelper, String, Object, Object) | Returns a hidden input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. | |
HiddenFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>) | Returns an HTML hidden input element for each property in the object that is represented by the specified expression. | |
HiddenFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, IDictionary<String, Object>) | Returns an HTML hidden input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
HiddenFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, Object) | Returns an HTML hidden input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
Password(HtmlHelper, String) | Returns a password input element by using the specified HTML helper and the name of the form field. | |
Password(HtmlHelper, String, Object) | Returns a password input element by using the specified HTML helper, the name of the form field, and the value. | |
Password(HtmlHelper, String, Object, IDictionary<String, Object>) | Returns a password input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. | |
Password(HtmlHelper, String, Object, Object) | Returns a password input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. | |
PasswordFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>) | Returns a password input element for each property in the object that is represented by the specified expression. | |
PasswordFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, IDictionary<String, Object>) | Returns a password input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
PasswordFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, Object) | Returns a password input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
RadioButton(HtmlHelper, String, Object) | Returns a radio button input element that is used to present mutually exclusive options. | |
RadioButton(HtmlHelper, String, Object, Boolean) | Returns a radio button input element that is used to present mutually exclusive options. | |
RadioButton(HtmlHelper, String, Object, IDictionary<String, Object>) | Returns a radio button input element that is used to present mutually exclusive options. | |
RadioButton(HtmlHelper, String, Object, Object) | Returns a radio button input element that is used to present mutually exclusive options. | |
RadioButton(HtmlHelper, String, Object, Boolean, IDictionary<String, Object>) | Returns a radio button input element that is used to present mutually exclusive options. | |
RadioButton(HtmlHelper, String, Object, Boolean, Object) | Returns a radio button input element that is used to present mutually exclusive options. | |
RadioButtonFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, Object) | Returns a radio button input element for each property in the object that is represented by the specified expression. | |
RadioButtonFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, Object, IDictionary<String, Object>) | Returns a radio button input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
RadioButtonFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, Object, Object) | Returns a radio button input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
TextBox(HtmlHelper, String) | Returns a text input element by using the specified HTML helper and the name of the form field. | |
TextBox(HtmlHelper, String, Object) | Returns a text input element by using the specified HTML helper, the name of the form field, and the value. | |
TextBox(HtmlHelper, String, Object, IDictionary<String, Object>) | Returns a text input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. | |
TextBox(HtmlHelper, String, Object, Object) | Returns a text input element by using the specified HTML helper, the name of the form field, the value, and the HTML attributes. | |
TextBoxFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>) | Returns a text input element for each property in the object that is represented by the specified expression. | |
TextBoxFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, IDictionary<String, Object>) | Returns a text input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. | |
TextBoxFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, Object) | Returns a text input element for each property in the object that is represented by the specified expression, using the specified HTML attributes. |
Top
Remarks
The InputExtensions class contains methods that extend the HtmlHelper class. Each extension method renders an HTML input element. With the exception of the Password extension method, each extension method can repopulate its values from the posted values by using the ModelState object. The following input element types are available in this class:
Examples
The following example shows how to use the methods of the InputExtensions class. The view displays a text box, a password box, some radio buttons, and some check boxes.
<h2><%= Html.Encode(ViewData("Message")) %></h2>
<br /><br />
<% Using Html.BeginForm("Input", "Home")%>
Enter your name: <%= Html.TextBox("name") %>
<br /><br />
Enter a password: <%= Html.Password("pass") %> (Not actually used.)
<br /><br />
Select your favorite color:<br />
<%= Html.RadioButton("favColor", "Blue", true) %> Blue <br />
<%= Html.RadioButton("favColor", "Purple", false)%> Purple <br />
<%= Html.RadioButton("favColor", "Red", false)%> Red <br />
<%= Html.RadioButton("favColor", "Orange", false)%> Orange <br />
<%= Html.RadioButton("favColor", "Yellow", false)%> Yellow <br />
<%= Html.RadioButton("favColor", "Brown", false)%> Brown <br />
<%= Html.RadioButton("favColor", "Green", false)%> Green
<br /><br />
<%= Html.CheckBox("technical") %> I like to read technical books.<br />
<%= Html.CheckBox("novels") %> I like to read novels.<br />
<%= Html.CheckBox("comic") %> I like to read comic books.<br />
<br /><br />
<input type="submit" value="Submit" />
<% End Using%>
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<br /><br />
<% using(Html.BeginForm("Input", "Home")) %>
<% { %>
Enter your name: <%= Html.TextBox("name") %>
<br /><br />
Enter a password: <%= Html.Password("pass") %> (Not actually used.)
<br /><br />
Select your favorite color:<br />
<%= Html.RadioButton("favColor", "Blue", true) %> Blue <br />
<%= Html.RadioButton("favColor", "Purple", false)%> Purple <br />
<%= Html.RadioButton("favColor", "Red", false)%> Red <br />
<%= Html.RadioButton("favColor", "Orange", false)%> Orange <br />
<%= Html.RadioButton("favColor", "Yellow", false)%> Yellow <br />
<%= Html.RadioButton("favColor", "Brown", false)%> Brown <br />
<%= Html.RadioButton("favColor", "Green", false)%> Green
<br /><br />
<%= Html.CheckBox("technical") %> I like to read technical books.<br />
<%= Html.CheckBox("novels") %> I like to read novels.<br />
<%= Html.CheckBox("comic") %> I like to read comic books.<br />
<br /><br />
<input type="submit" value="Submit" />
<% } %>
The following example shows a form. When the user submits the form, the Input action method processes the form data and renders a view.
Function Input(ByVal name As String, ByVal pass As String, _
ByVal favColor As String, ByVal technical As Boolean, _
ByVal novels As Boolean, _
ByVal comic As Boolean) As ActionResult
ViewData("name") = name
ViewData("favColor") = favColor
Dim bookMsg As String = ""
If (technical) Then bookMsg = "You read technical books.<br />"
If (novels) Then bookMsg = bookMsg + "You read novels.<br />"
If (comic) Then bookMsg = bookMsg + "You read comic books."
ViewData("books") = bookMsg
Return View()
End Function
public ActionResult Input(string name, string pass,
string favColor, Boolean technical, Boolean novels,
Boolean comic)
{
ViewData["name"] = name;
ViewData["favColor"] = favColor;
string bookMsg = "";
if (technical) bookMsg = "You read tehnical books.<br />";
if (novels) bookMsg += "You read novels.<br />";
if (comic) bookMsg += "You read comic books.";
ViewData["books"] = bookMsg;
return View();
}
In the following example, the view displays the data that was submitted.
<h2>HTML Input Extensions</h2>
<p>Hello, <b><%=Html.Encode(ViewData("name"))%></b></p>
<p>Your favorite color: <b><%=Html.Encode(ViewData("favColor"))%></b></p>
<p><%=ViewData("books")%></p>
<h2>HTML Input Extensions</h2>
<p>Hello, <b><%= Html.Encode(ViewData["name"])%></b></p>
<p>Your favorite color: <b><%= Html.Encode(ViewData["favColor"]) %></b></p>
<p><%= ViewData["books"] %></p>
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.