IHtmlHelper<TModel> Interface¶
An Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper
for Linq expressions.
- Namespace
Microsoft.AspNetCore.Mvc.Rendering
- Assemblies
- Microsoft.AspNetCore.Mvc.ViewFeatures
Syntax¶
public interface IHtmlHelper<TModel> : IHtmlHelper
-
interface
Microsoft.AspNetCore.Mvc.Rendering.
IHtmlHelper<TModel>
¶
Methods¶
-
CheckBoxFor
(System.Linq.Expressions.Expression<System.Func<TModel, System.Boolean>>, System.Object)¶ Returns an <input> element of type “checkbox” with value “true” and an <input> element of type “hidden” with value “false”.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, System.Boolean>>) – An expression to be evaluated against the current model.
- htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the checkbox element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <input> elements.IHtmlContent CheckBoxFor(Expression<Func<TModel, bool>> expression, object htmlAttributes)
-
DisplayFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.String, System.Object)¶ Returns HTML markup for the <em>expression</em>, using a display template, specified HTML field name, and additional view data. The template is found using the <em>templateName</em> or the <em>expression</em>’s
Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata
.Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- templateName (System.String) – The name of the template used to create the HTML markup.
- htmlFieldName (System.String) – A
System.String
used to disambiguate the names of HTML elements that are created for properties that have the same name. - additionalViewData (System.Object) – An anonymous
System.Object
orSystem.Collections.Generic.IDictionary`2
that can contain additional view data that will be merged into theMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1
instance created for the template.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the created HTML.IHtmlContent DisplayFor<TResult>(Expression<Func<TModel, TResult>> expression, string templateName, string htmlFieldName, object additionalViewData)
-
DisplayNameForInnerType<TModelItem, TResult>
(System.Linq.Expressions.Expression<System.Func<TModelItem, TResult>>)¶ Returns the display name for the specified <em>expression</em> if the current model represents a collection.
Arguments: expression (System.Linq.Expressions.Expression<System.Func<TModelItem, TResult>>) – An expression to be evaluated against an item in the current model. Return type: System.String Returns: A System.String
containing the display name.string DisplayNameForInnerType<TModelItem, TResult>(Expression<Func<TModelItem, TResult>> expression)
-
DisplayNameFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)¶ Returns the display name for the specified <em>expression</em>.
Arguments: expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model. Return type: System.String Returns: A System.String
containing the display name.string DisplayNameFor<TResult>(Expression<Func<TModel, TResult>> expression)
-
DisplayTextFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)¶ Returns the simple display text for the specified <em>expression</em>.
Arguments: expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model. Return type: System.String Returns: A System.String
containing the simple display text. If the <em>expression</em> result is <code>null</code>, returnsMicrosoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.NullDisplayText
.string DisplayTextFor<TResult>(Expression<Func<TModel, TResult>> expression)
-
DropDownListFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>, System.String, System.Object)¶ Returns a single-selection HTML <select> element for the <em>expression</em>, using the specified list items, option label, and HTML attributes.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- selectList (System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>) – A collection of
Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
objects used to populate the <select> element with <optgroup> and <option> elements. - optionLabel (System.String) – The text for a default empty item. Does not include such an item if argument is <code>null</code>.
- htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the <select> element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <select> element.IHtmlContent DropDownListFor<TResult>(Expression<Func<TModel, TResult>> expression, IEnumerable<SelectListItem> selectList, string optionLabel, object htmlAttributes)
-
EditorFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.String, System.Object)¶ Returns HTML markup for the <em>expression</em>, using an editor template, specified HTML field name, and additional view data. The template is found using the <em>templateName</em> or the <em>expression</em>’s
Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata
.Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- templateName (System.String) – The name of the template that is used to create the HTML markup.
- htmlFieldName (System.String) – A
System.String
used to disambiguate the names of HTML elements that are created for properties that have the same name. - additionalViewData (System.Object) – An anonymous
System.Object
orSystem.Collections.Generic.IDictionary`2
that can contain additional view data that will be merged into theMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1
instance created for the template.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <input> element(s).IHtmlContent EditorFor<TResult>(Expression<Func<TModel, TResult>> expression, string templateName, string htmlFieldName, object additionalViewData)
-
Encode
(System.Object)¶ Return type: System.String string Encode(object value)
-
Encode
(System.String) Return type: System.String string Encode(string value)
-
HiddenFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Object)¶ Returns an <input> element of type “hidden” for the specified <em>expression</em>.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <input> element.IHtmlContent HiddenFor<TResult>(Expression<Func<TModel, TResult>> expression, object htmlAttributes)
-
IdFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)¶ Returns the HTML element Id for the specified <em>expression</em>.
Arguments: expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model. Return type: System.String Returns: A System.String
containing the element Id.string IdFor<TResult>(Expression<Func<TModel, TResult>> expression)
-
LabelFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.Object)¶ Returns a <label> element for the specified <em>expression</em>.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- labelText (System.String) – The inner text of the element.
- htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <label> element.IHtmlContent LabelFor<TResult>(Expression<Func<TModel, TResult>> expression, string labelText, object htmlAttributes)
-
ListBoxFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>, System.Object)¶ Returns a multi-selection <select> element for the <em>expression</em>, using the specified list items and HTML attributes.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- selectList (System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>) – A collection of
Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
objects used to populate the <select> element with <optgroup> and <option> elements. - htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the <select> element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <select> element.IHtmlContent ListBoxFor<TResult>(Expression<Func<TModel, TResult>> expression, IEnumerable<SelectListItem> selectList, object htmlAttributes)
-
NameFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)¶ Returns the full HTML element name for the specified <em>expression</em>.
Arguments: expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model. Return type: System.String Returns: A System.String
containing the element name.string NameFor<TResult>(Expression<Func<TModel, TResult>> expression)
-
PasswordFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Object)¶ Returns an <input> element of type “password” for the specified <em>expression</em>.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <input> element.IHtmlContent PasswordFor<TResult>(Expression<Func<TModel, TResult>> expression, object htmlAttributes)
-
RadioButtonFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Object, System.Object)¶ Returns an <input> element of type “radio” for the specified <em>expression</em>.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- value (System.Object) – Value to include in the element. Must not be <code>null</code>.
- htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <input> element.IHtmlContent RadioButtonFor<TResult>(Expression<Func<TModel, TResult>> expression, object value, object htmlAttributes)
-
Raw
(System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent IHtmlContent Raw(object value)
-
Raw
(System.String) Return type: Microsoft.AspNetCore.Html.IHtmlContent IHtmlContent Raw(string value)
-
TextAreaFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Int32, System.Int32, System.Object)¶ Returns a <textarea> element for the specified <em>expression</em>.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- rows (System.Int32) – Number of rows in the textarea.
- columns (System.Int32) – Number of columns in the textarea.
- htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <textarea> element.IHtmlContent TextAreaFor<TResult>(Expression<Func<TModel, TResult>> expression, int rows, int columns, object htmlAttributes)
-
TextBoxFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.Object)¶ Returns an <input> element of type “text” for the specified <em>expression</em>.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- format (System.String) – The composite format
System.String
(see http://msdn.microsoft.com/en-us/library/txafckwd.aspx). - htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <input> element.IHtmlContent TextBoxFor<TResult>(Expression<Func<TModel, TResult>> expression, string format, object htmlAttributes)
-
ValidationMessageFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.Object, System.String)¶ Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
object for the specified <em>expression</em>.Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- message (System.String) – The message to be displayed. If <code>null</code> or empty, method extracts an error string from the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
object. Message will always be visible but client-side validation may update the associated CSS class. - htmlAttributes (System.Object) – An
System.Object
that contains the HTML attributes for the <em>tag</em> element. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes. - tag (System.String) – The tag to wrap the <em>message</em> in the generated HTML. Its default value is
Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElement
.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContent
containing the <em>tag</em> element. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.IHtmlContent ValidationMessageFor<TResult>(Expression<Func<TModel, TResult>> expression, string message, object htmlAttributes, string tag)
-
ValueFor<TResult>
(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String)¶ Returns the formatted value for the specified <em>expression</em>.
Arguments: - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- format (System.String) – The composite format
System.String
(see http://msdn.microsoft.com/en-us/library/txafckwd.aspx).
Return type: System.String
Returns: A
System.String
containing the formatted value.string ValueFor<TResult>(Expression<Func<TModel, TResult>> expression, string format)
-
Properties¶
-
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>.
ViewData
¶ Gets the current view data.
Return type: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<TModel> ViewDataDictionary<TModel> ViewData { get; }
-