Professional ASP.NET MVC 4
by Jon Galloway, Phil Haack, Brad Wilson, K. Scott Allen, Scott Hanselman
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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access