Export (0) Print
Expand All

InputExtensions.RadioButton Method (HtmlHelper, String, Object, Boolean, Object)

Returns a radio button input element that is used to present mutually exclusive options.

Namespace:  System.Web.Mvc.Html
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

public static string RadioButton(
	this HtmlHelper htmlHelper,
	string name,
	Object value,
	bool isChecked,
	Object htmlAttributes
)

Parameters

htmlHelper
Type: System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
name
Type: System.String
The name of the form field and the ViewDataDictionary key that is used to look up the value.
value
Type: System.Object
If this radio button is selected, the value of the radio button that is submitted when the form is posted. If the value of the selected radio button in the ViewDataDictionary or the ModelStateDictionary object matches this value, this radio button is selected.
isChecked
Type: System.Boolean
true to select the radio button; otherwise, false.
htmlAttributes
Type: System.Object
An object that contains the HTML attributes for the element. The attributes are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.

Return Value

Type: System.String
An input element that has its type attribute set to "radio".

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type HtmlHelper. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

ExceptionCondition
[ArgumentException]

The name parameter is null or empty.

[ArgumentNullException]

The value parameter is null (Nothing in Visual Basic).

Radio buttons are used when you want to let the user select one, and only one, option from a set of alternatives. If more than one option must be allowed at a time, you should use check boxes instead.

Community Additions

Show:
© 2014 Microsoft