IHtmlHelper<TModel> Interface

Summary

An [Microsoft.AspNet.Mvc.Rendering.IHtmlHelper](Microsoft.AspNet.Mvc.Rendering.IHtmlHelper.yml) for Linq expressions.

Syntax

public interface IHtmlHelper<TModel> : IHtmlHelper

GitHub

View on GitHub

Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>

Properties

ViewData()

Gets the current view data.

Return type:Microsoft.AspNet.Mvc.ViewDataDictionary{{TModel}}
ViewDataDictionary<TModel> ViewData { get; }

Methods

CheckBoxFor(System.Linq.Expressions.Expression<System.Func<TModel, System.Boolean>>, System.Object)

Returns an &lt;input&gt; element of type “checkbox” with value “true” and an &lt;input&gt; 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, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;input&gt; elements.

HtmlString CheckBoxFor(Expression<Func<TModel, bool>> expression, object htmlAttributes)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.DisplayFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.String, System.Object)

Returns HTML markup for the <paramref name=”expression” />, using a display template, specified HTML field name, and additional view data. The template is found using the <paramref name=”templateName” /> or the

<paramref name=”expression” />’s [Microsoft.AspNet.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]() or [System.Collections.Generic.IDictionary`2]() that can contain additional view data that will be merged into the [Microsoft.AspNet.Mvc.ViewDataDictionary`1](Microsoft.AspNet.Mvc.ViewDataDictionary`1.yml) instance created for the template.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the created HTML.

HtmlString DisplayFor<TResult>(Expression<Func<TModel, TResult>> expression, string templateName, string htmlFieldName, object additionalViewData)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.DisplayNameForInnerType<TModelItem, TResult>(System.Linq.Expressions.Expression<System.Func<TModelItem, TResult>>)

Returns the display name for the specified <paramref name=”expression” /> 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)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.DisplayNameFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)

Returns the display name for the specified <paramref name=”expression” />.

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)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.DisplayTextFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)

Returns the simple display text for the specified <paramref name=”expression” />.

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 <paramref name=”expression” /> result is <c>null</c>, returns [Microsoft.AspNet.Mvc.ModelBinding.ModelMetadata.NullDisplayText]().

string DisplayTextFor<TResult>(Expression<Func<TModel, TResult>> expression)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.DropDownListFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Collections.Generic.IEnumerable<Microsoft.AspNet.Mvc.Rendering.SelectListItem>, System.String, System.Object)

Returns a single-selection HTML &lt;select&gt; element for the <paramref name=”expression” />, 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.AspNet.Mvc.Rendering.SelectListItem}) – A collection of [Microsoft.AspNet.Mvc.Rendering.SelectListItem](Microsoft.AspNet.Mvc.Rendering.SelectListItem.yml) objects used to populate the &lt;select&gt; element with &lt;optgroup&gt; and &lt;option&gt; elements.
  • optionLabel (System.String) – The text for a default empty item. Does not include such an item if argument is <c>null</c>.
  • htmlAttributes (System.Object) – An [System.Object]() that contains the HTML attributes for the &lt;select&gt; element. Alternatively, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;select&gt; element.

HtmlString DropDownListFor<TResult>(Expression<Func<TModel, TResult>> expression, IEnumerable<SelectListItem> selectList, string optionLabel, object htmlAttributes)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.EditorFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.String, System.Object)

Returns HTML markup for the <paramref name=”expression” />, using an editor template, specified HTML field name, and additional view data. The template is found using the <paramref name=”templateName” /> or the

<paramref name=”expression” />’s [Microsoft.AspNet.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]() or [System.Collections.Generic.IDictionary`2]() that can contain additional view data that will be merged into the [Microsoft.AspNet.Mvc.ViewDataDictionary`1](Microsoft.AspNet.Mvc.ViewDataDictionary`1.yml) instance created for the template.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;input&gt; element(s).

HtmlString EditorFor<TResult>(Expression<Func<TModel, TResult>> expression, string templateName, string htmlFieldName, object additionalViewData)
Encode(System.Object)
Arguments:
  • value (System.Object) –
Return type:

System.String

string Encode(object value)
Encode(System.String)
Arguments:
  • value (System.String) –
Return type:

System.String

string Encode(string value)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.HiddenFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Object)

Returns an &lt;input&gt; element of type “hidden” for the specified <paramref name=”expression” />.

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, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;input&gt; element.

HtmlString HiddenFor<TResult>(Expression<Func<TModel, TResult>> expression, object htmlAttributes)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.IdFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)

Returns the HTML element Id for the specified <paramref name=”expression” />.

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)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.LabelFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.Object)

Returns a &lt;label&gt; element for the specified <paramref name=”expression” />.

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, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;label&gt; element.

HtmlString LabelFor<TResult>(Expression<Func<TModel, TResult>> expression, string labelText, object htmlAttributes)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.ListBoxFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Collections.Generic.IEnumerable<Microsoft.AspNet.Mvc.Rendering.SelectListItem>, System.Object)

Returns a multi-selection &lt;select&gt; element for the <paramref name=”expression” />, 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.AspNet.Mvc.Rendering.SelectListItem}) – A collection of [Microsoft.AspNet.Mvc.Rendering.SelectListItem](Microsoft.AspNet.Mvc.Rendering.SelectListItem.yml) objects used to populate the &lt;select&gt; element with &lt;optgroup&gt; and &lt;option&gt; elements.
  • htmlAttributes (System.Object) – An [System.Object]() that contains the HTML attributes for the &lt;select&gt; element. Alternatively, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;select&gt; element.

HtmlString ListBoxFor<TResult>(Expression<Func<TModel, TResult>> expression, IEnumerable<SelectListItem> selectList, object htmlAttributes)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.NameFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)

Returns the full HTML element name for the specified <paramref name=”expression” />.

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)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.PasswordFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Object)

Returns an &lt;input&gt; element of type “password” for the specified <paramref name=”expression” />.

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, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;input&gt; element.

HtmlString PasswordFor<TResult>(Expression<Func<TModel, TResult>> expression, object htmlAttributes)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.RadioButtonFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Object, System.Object)

Returns an &lt;input&gt; element of type “radio” for the specified <paramref name=”expression” />.

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 <c>null</c>.
  • htmlAttributes (System.Object) – An [System.Object]() that contains the HTML attributes for the element. Alternatively, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;input&gt; element.

HtmlString RadioButtonFor<TResult>(Expression<Func<TModel, TResult>> expression, object value, object htmlAttributes)
Raw(System.Object)
Arguments:
  • value (System.Object) –
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

HtmlString Raw(object value)
Raw(System.String)
Arguments:
  • value (System.String) –
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

HtmlString Raw(string value)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.TextAreaFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.Int32, System.Int32, System.Object)

Returns a &lt;textarea&gt; element for the specified <paramref name=”expression” />.

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, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;textarea&gt; element.

HtmlString TextAreaFor<TResult>(Expression<Func<TModel, TResult>> expression, int rows, int columns, object htmlAttributes)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.TextBoxFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.Object)

Returns an &lt;input&gt; element of type “text” for the specified <paramref name=”expression” />.

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, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the &lt;input&gt; element.

HtmlString TextBoxFor<TResult>(Expression<Func<TModel, TResult>> expression, string format, object htmlAttributes)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.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.AspNet.Mvc.ModelBinding.ModelStateDictionary]() object for the specified <paramref name=”expression” />.

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 <c>null</c> or empty, method extracts an error string from the [Microsoft.AspNet.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 <paramref name=”tag” /> element. Alternatively, an [System.Collections.Generic.IDictionary`2]() instance containing the HTML attributes.
  • tag (System.String) – The tag to wrap the <paramref name=”message” /> in the generated HTML. Its default value is [Microsoft.AspNet.Mvc.ViewContext.ValidationMessageElement](Microsoft.AspNet.Mvc.ViewContext.yml).
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

A new [Microsoft.AspNet.Mvc.Rendering.HtmlString](Microsoft.AspNet.Mvc.Rendering.HtmlString.yml) containing the <paramref name=”tag” /> element. <c>null</c> if the <paramref name=”expression” /> is valid and client-side validation is disabled.

HtmlString ValidationMessageFor<TResult>(Expression<Func<TModel, TResult>> expression, string message, object htmlAttributes, string tag)
Microsoft.AspNet.Mvc.Rendering.IHtmlHelper<TModel>.ValueFor<TResult>(System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String)

Returns the formatted value for the specified <paramref name=”expression” />.

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)