Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CheckBox Method

InputExtensions.CheckBox Method

 

Returns a check box input element that enables the user to select a true or false condition.

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

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCheckBox(HtmlHelper, String)

Returns a check box input element by using the specified HTML helper and the name of the form field.

System_CAPS_pubmethodSystem_CAPS_staticCheckBox(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.

System_CAPS_pubmethodSystem_CAPS_staticCheckBox(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.

System_CAPS_pubmethodSystem_CAPS_staticCheckBox(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.

System_CAPS_pubmethodSystem_CAPS_staticCheckBox(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.

System_CAPS_pubmethodSystem_CAPS_staticCheckBox(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.

In addition to rendering a check box input element, this method renders a hidden input element so that an unselected check box will return false.

The difference between calling the CheckBox method and using an input element is that the CheckBox method is designed to make it easy to bind to view data or model data.

Return to top

InputExtensions.CheckBox Method (HtmlHelper, String)

Returns a check box input element by using the specified HTML helper and the name of the form field.

public static MvcHtmlString CheckBox(
	this HtmlHelper htmlHelper,
	string name
)

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.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An input element whose type attribute is set to "checkbox".

In addition to rendering a check box input element, this method renders a hidden input element so that an unselected check box will return false.

The difference between calling the CheckBox method and using an input element is that the CheckBox method is designed to make it easy to bind to view data or model data.

Return to top

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

public static MvcHtmlString CheckBox(
	this HtmlHelper htmlHelper,
	string name,
	bool isChecked
)

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.

isChecked
Type: System.Boolean

true to select the check box; otherwise, false. The value of the check box is retrieved in this order - the ModelStateDictionary object, the value of this parameter, the ViewDataDictionary object, and lastly, a checked attribute in the html attributes.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An input element whose type attribute is set to "checkbox".

In addition to rendering a check box input element, this method renders a hidden input element so that an unselected check box will return false.

The difference between calling the CheckBox method and using an input element is that the CheckBox method is designed to make it easy to bind to view data or model data.

Return to top

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

public static MvcHtmlString CheckBox(
	this HtmlHelper htmlHelper,
	string name,
	bool isChecked,
	IDictionary<stringobject> 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.

isChecked
Type: System.Boolean

true to select the check box; otherwise, false. The value of the check box is retrieved in this order - the ModelStateDictionary object, the value of this parameter, the ViewDataDictionary object, and lastly, a checked attribute in the html attributes.

htmlAttributes
Type: System.Collections.Generic.IDictionary<StringObject>

An object that contains the HTML attributes to set for the element.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An input element whose type attribute is set to "checkbox".

In addition to rendering a check box input element, this method renders a hidden input element so that an unselected check box will return false.

The difference between calling the CheckBox method and using an input element is that the CheckBox method is designed to make it easy to bind to view data or model data.

The htmlAttributes parameter consists of an object that contains name/value pairs. The attributes that are specified in the name/value pairs depend on the HTML element that is being rendered. For example, for an input element where type is set to "checkbox", you might provide the following anonymous object:

new { id = "checkbox1" }
Return to top

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.

public static MvcHtmlString CheckBox(
	this HtmlHelper htmlHelper,
	string name,
	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.

isChecked
Type: System.Boolean

true to select the check box; otherwise, false. The value of the check box is retrieved in this order - the ModelStateDictionary object, the value of this parameter, the ViewDataDictionary object, and lastly, a checked attribute in the html attributes.

htmlAttributes
Type: System.Object

An object that contains the HTML attributes to set for the element.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An input element whose type attribute is set to "checkbox".

In addition to rendering a check box input element, this method renders a hidden input element so that an unselected check box will return false.

The difference between calling the CheckBox method and using an input element is that the CheckBox method is designed to make it easy to bind to view data or model data.

The htmlAttributes parameter consists of an object that contains name/value pairs. The attributes that are specified in the name/value pairs depend on the HTML element that is being rendered. For example, for an input element where type is set to "checkbox", you might provide the following anonymous object:

new { id = "checkbox1" }
Return to top

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

public static MvcHtmlString CheckBox(
	this HtmlHelper htmlHelper,
	string name,
	IDictionary<stringobject> 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.

htmlAttributes
Type: System.Collections.Generic.IDictionary<StringObject>

An object that contains the HTML attributes to set for the element.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An input element whose type attribute is set to "checkbox".

In addition to rendering a check box input element, this method renders a hidden input element so that an unselected check box will return false.

The difference between calling the CheckBox method and using an input element is that the CheckBox method is designed to make it easy to bind to view data or model data.

The htmlAttributes parameter consists of an object that contains name/value pairs. The attributes that are specified in the name/value pairs depend on the HTML element that is being rendered. For example, for an input element where type is set to "checkbox", you might provide the following anonymous object:

new { id = "checkbox1" }
Return to top

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

public static MvcHtmlString CheckBox(
	this HtmlHelper htmlHelper,
	string name,
	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.

htmlAttributes
Type: System.Object

An object that contains the HTML attributes to set for the element.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An input element whose type attribute is set to "checkbox".

In addition to rendering a check box input element, this method renders a hidden input element so that an unselected check box will return false.

The difference between calling the CheckBox method and using an input element is that the CheckBox method is designed to make it easy to bind to view data or model data.

The htmlAttributes parameter consists of an object that contains name/value pairs. The attributes that are specified in the name/value pairs depend on the HTML element that is being rendered. For example, for an input element where type is set to "checkbox", you might provide the following anonymous object:

new { id = "checkbox1" }
Return to top
Show:
© 2015 Microsoft