Dela via


IHtmlHelper.CheckBox(String, Nullable<Boolean>, Object) Method

Definition

Returns an <input> element of type "checkbox" with value "true" and an <input> element of type "hidden" with value "false" for the specified expression. Adds a "checked" attribute to the "checkbox" element based on the first non-null value found in: the htmlAttributes dictionary entry with key "checked", the ModelState entry with full name, the ViewData entry with full name, or the expression evaluated against Model. If isChecked is non-null, instead uses the first non-null value found in: the ModelState entry with full name, or the isChecked parameter. See Name(String) for more information about a "full name".

public:
 Microsoft::AspNetCore::Html::IHtmlContent ^ CheckBox(System::String ^ expression, Nullable<bool> isChecked, System::Object ^ htmlAttributes);
public Microsoft.AspNetCore.Html.IHtmlContent CheckBox (string expression, bool? isChecked, object htmlAttributes);
abstract member CheckBox : string * Nullable<bool> * obj -> Microsoft.AspNetCore.Html.IHtmlContent
Public Function CheckBox (expression As String, isChecked As Nullable(Of Boolean), htmlAttributes As Object) As IHtmlContent

Parameters

expression
String

Expression name, relative to the current model.

isChecked
Nullable<Boolean>

If true, checkbox is initially checked.

htmlAttributes
Object

An Object that contains the HTML attributes for the checkbox element. Alternatively, an IDictionary<TKey,TValue> instance containing the HTML attributes.

Returns

A new IHtmlContent containing the <input> elements.

Remarks

Combines HtmlFieldPrefix and expression to set checkbox element's "name" attribute. Sanitizes expression to set checkbox element's "id" attribute.

Applies to