InputExtensions.CheckBox Method
Returns a check box input element that enables the user to select a true or false condition.
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
| Name | Description | |
|---|---|---|
![]() ![]() | CheckBox(HtmlHelper, String) | Returns a check box input element by using the specified HTML helper and the name of the form field. |
![]() ![]() | CheckBox(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. |
![]() ![]() | CheckBox(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. |
![]() ![]() | CheckBox(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. |
![]() ![]() | CheckBox(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. |
![]() ![]() | CheckBox(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.
InputExtensions.CheckBox Method (HtmlHelper, String)
Returns a check box input element by using the specified HTML helper and the name of the form field.
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.MvcHtmlStringAn 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.
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.MvcHtmlStringAn 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.
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<string, 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.Collections.Generic.IDictionary<String, Object>
An object that contains the HTML attributes to set for the element.
Return Value
Type: System.Web.Mvc.MvcHtmlStringAn 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:
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.MvcHtmlStringAn 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:
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<string, 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.Collections.Generic.IDictionary<String, Object>
An object that contains the HTML attributes to set for the element.
Return Value
Type: System.Web.Mvc.MvcHtmlStringAn 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:
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.MvcHtmlStringAn 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:

