InputExtensions.CheckBox Method (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.

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

public static string CheckBox(
	this HtmlHelper htmlHelper,
	string name,
	bool isChecked,
	Object htmlAttributes


Type: System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
Type: System.String
The name of the form field.
Type: System.Boolean
true to select the check box; otherwise, false.
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 "checkbox".

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).

Check boxes are used when you want to let the user select one or more options from a set of alternatives. If only one option should be selected at a time, you should use radio buttons instead.

Community Additions