Other Input Helpers

In addition to the input helpers you've looked at so far, such as TextBox and DropDownList, the MVC framework contains a number of other helpers to cover the full range of input controls.

Html.Hidden

The Html.Hidden helper renders a hidden input. For example, the following code:

@Html.Hidden("wizardStep", "1")

results in:

<input id="wizardStep" name="wizardStep" type="hidden" value="1" />

The strongly typed version of this helper is Html.HiddenFor. Assuming your model had a WizardStep property, you would use it as follows:

@Html.HiddenFor(m => m.WizardStep)

Html.Password

The Html.Password helper renders a password field. It's much like the TextBox helper, except that it does not retain the posted value, and it uses a password mask. The following code:

@Html.Password("UserPassword")

results in:

<input id="UserPassword" name="UserPassword" type="password" value="" />

The strongly typed syntax for Html.Password, as you'd expect, is Html.PasswordFor. Here's how you'd use it to display the UserPassword property:

@Html.PasswordFor(m => m.UserPassword)

Html.RadioButton

Radio buttons are generally grouped together to provide a range of possible options for a single value. For example, if you want the user to select a color from a specific list of colors, you can use multiple radio buttons to present the choices. To group the radio buttons, you give each button the same name. Only the selected radio button is posted back to the server when the form is submitted. ...

Get Professional ASP.NET MVC 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.