Dela via


IHtmlHelper<TModel>.CheckBoxFor 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", or the ModelState entry with full name. If expression evaluates to a non-null value, instead uses the first non-null value found in: the ModelState entry with full name, or the expression evaluated against Model. See NameFor<TResult>(Expression<Func<TModel,TResult>>) for more information about a "full name".

public:
 Microsoft::AspNetCore::Html::IHtmlContent ^ CheckBoxFor(System::Linq::Expressions::Expression<Func<TModel, bool> ^> ^ expression, System::Object ^ htmlAttributes);
public Microsoft.AspNetCore.Html.IHtmlContent CheckBoxFor (System.Linq.Expressions.Expression<Func<TModel,bool>> expression, object htmlAttributes);
abstract member CheckBoxFor : System.Linq.Expressions.Expression<Func<'Model, bool>> * obj -> Microsoft.AspNetCore.Html.IHtmlContent
Public Function CheckBoxFor (expression As Expression(Of Func(Of TModel, Boolean)), htmlAttributes As Object) As IHtmlContent

Parameters

expression
Expression<Func<TModel,Boolean>>

An expression to be evaluated against the current model.

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 the string representation of the expression to set checkbox element's "name" attribute. Sanitizes the string representation of the expression to set checkbox element's "id" attribute.

Applies to