IHtmlGenerator Interface

Contract for a service supporting Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper and <code>ITagHelper</code> implementations.

Namespace
Microsoft.AspNetCore.Mvc.ViewFeatures
Assemblies
  • Microsoft.AspNetCore.Mvc.ViewFeatures

Syntax

public interface IHtmlGenerator
interface Microsoft.AspNetCore.Mvc.ViewFeatures.IHtmlGenerator

Methods

Encode(System.Object)
Return type:System.String
string Encode(object value)
Encode(System.String)
Return type:System.String
string Encode(string value)
FormatValue(System.Object, System.String)
Return type:System.String
string FormatValue(object value, string format)

Generate a <a> element for a link to an action.

Arguments:
  • viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – The Microsoft.AspNetCore.Mvc.Rendering.ViewContext instance for the current scope.
  • linkText (System.String) – The text to insert inside the element.
  • actionName (System.String) – The name of the action method.
  • controllerName (System.String) – The name of the controller.
  • protocol (System.String) – The protocol (scheme) for the generated link.
  • hostname (System.String) – The hostname for the generated link.
  • fragment (System.String) – The fragment for the genrated link.
  • routeValues (System.Object) – An System.Object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the System.Object. This System.Object is typically created using System.Object initializer syntax. Alternatively, an System.Collections.Generic.IDictionary`2 instance containing the route parameters.
  • 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.AspNetCore.Mvc.Rendering.TagBuilder

Returns:

A Microsoft.AspNetCore.Mvc.Rendering.TagBuilder instance for the <a> element.

TagBuilder GenerateActionLink(ViewContext viewContext, string linkText, string actionName, string controllerName, string protocol, string hostname, string fragment, object routeValues, object htmlAttributes)
GenerateAntiforgery(Microsoft.AspNetCore.Mvc.Rendering.ViewContext)

Generate an <input type=”hidden”.../> element containing an antiforgery token.

Arguments:viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – The Microsoft.AspNetCore.Mvc.Rendering.ViewContext instance for the current scope.
Return type:Microsoft.AspNetCore.Html.IHtmlContent
Returns:An Microsoft.AspNetCore.Html.IHtmlContent instance for the <input type=”hidden”.../> element. Intended to be used inside a <form> element.
IHtmlContent GenerateAntiforgery(ViewContext viewContext)
GenerateCheckBox(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Nullable<System.Boolean>, System.Object)

Generate a <input type=”checkbox”.../> element.

Arguments:
Return type:

Microsoft.AspNetCore.Mvc.Rendering.TagBuilder

Returns:

A Microsoft.AspNetCore.Mvc.Rendering.TagBuilder instance for the <input type=”checkbox”.../> element.

TagBuilder GenerateCheckBox(ViewContext viewContext, ModelExplorer modelExplorer, string expression, bool ? isChecked, object htmlAttributes)
GenerateForm(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, System.String, System.String, System.Object, System.String, System.Object)

Generate a <form> element. When the user submits the form, the action with name <em>actionName</em> will process the request.

Arguments:
  • viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A Microsoft.AspNetCore.Mvc.Rendering.ViewContext instance for the current scope.
  • actionName (System.String) – The name of the action method.
  • controllerName (System.String) – The name of the controller.
  • routeValues (System.Object) – An System.Object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the System.Object. This System.Object is typically created using System.Object initializer syntax. Alternatively, an System.Collections.Generic.IDictionary`2 instance containing the route parameters.
  • method (System.String) – The HTTP method for processing the form, either GET or POST.
  • 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.AspNetCore.Mvc.Rendering.TagBuilder

Returns:

A Microsoft.AspNetCore.Mvc.Rendering.TagBuilder instance for the </form> element.

TagBuilder GenerateForm(ViewContext viewContext, string actionName, string controllerName, object routeValues, string method, object htmlAttributes)
GenerateGroupsAndOptions(System.String, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>)

Generates <optgroup> and <option> elements.

Arguments:
Return type:

Microsoft.AspNetCore.Html.IHtmlContent

Returns:

An Microsoft.AspNetCore.Html.IHtmlContent instance for <optgroup> and <option> elements.

IHtmlContent GenerateGroupsAndOptions(string optionLabel, IEnumerable<SelectListItem> selectList)
GenerateHidden(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Object, System.Boolean, System.Object)
Return type:Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
TagBuilder GenerateHidden(ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, bool useViewData, object htmlAttributes)
GenerateHiddenForCheckbox(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String)

Generate an additional <input type=”hidden”.../> for checkboxes. This addresses scenarios where unchecked checkboxes are not sent in the request. Sending a hidden input makes it possible to know that the checkbox was present on the page when the request was submitted.

Return type:Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
TagBuilder GenerateHiddenForCheckbox(ViewContext viewContext, ModelExplorer modelExplorer, string expression)
GenerateLabel(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.String, System.Object)
Return type:Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
TagBuilder GenerateLabel(ViewContext viewContext, ModelExplorer modelExplorer, string expression, string labelText, object htmlAttributes)
GeneratePassword(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Object, System.Object)
Return type:Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
TagBuilder GeneratePassword(ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, object htmlAttributes)
GenerateRadioButton(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Object, System.Nullable<System.Boolean>, System.Object)
Return type:Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
TagBuilder GenerateRadioButton(ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, bool ? isChecked, object htmlAttributes)
GenerateRouteForm(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, System.String, System.Object, System.String, System.Object)

Generate a <form> element. The route with name <em>routeName</em> generates the <form>’s <code>action</code> attribute value.

Arguments:
  • viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A Microsoft.AspNetCore.Mvc.Rendering.ViewContext instance for the current scope.
  • routeName (System.String) – The name of the route.
  • routeValues (System.Object) – An System.Object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the System.Object. This System.Object is typically created using System.Object initializer syntax. Alternatively, an System.Collections.Generic.IDictionary`2 instance containing the route parameters.
  • method (System.String) – The HTTP method for processing the form, either GET or POST.
  • 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.AspNetCore.Mvc.Rendering.TagBuilder

Returns:

A Microsoft.AspNetCore.Mvc.Rendering.TagBuilder instance for the </form> element.

TagBuilder GenerateRouteForm(ViewContext viewContext, string routeName, object routeValues, string method, object htmlAttributes)

Generate a <a> element for a link to an action.

Arguments:
  • viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – The Microsoft.AspNetCore.Mvc.Rendering.ViewContext instance for the current scope.
  • linkText (System.String) – The text to insert inside the element.
  • routeName (System.String) – The name of the route to use for link generation.
  • protocol (System.String) – The protocol (scheme) for the generated link.
  • hostName (System.String) – The hostname for the generated link.
  • fragment (System.String) – The fragment for the genrated link.
  • routeValues (System.Object) – An System.Object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the System.Object. This System.Object is typically created using System.Object initializer syntax. Alternatively, an System.Collections.Generic.IDictionary`2 instance containing the route parameters.
  • 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.AspNetCore.Mvc.Rendering.TagBuilder

Returns:

A Microsoft.AspNetCore.Mvc.Rendering.TagBuilder instance for the <a> element.

TagBuilder GenerateRouteLink(ViewContext viewContext, string linkText, string routeName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)
GenerateSelect(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.String, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>, System.Boolean, System.Object)

Generate a <select> element for the <em>expression</em>.

Arguments:
Return type:

Microsoft.AspNetCore.Mvc.Rendering.TagBuilder

Returns:

A new Microsoft.AspNetCore.Mvc.Rendering.TagBuilder describing the <select> element.

TagBuilder GenerateSelect(ViewContext viewContext, ModelExplorer modelExplorer, string optionLabel, string expression, IEnumerable<SelectListItem> selectList, bool allowMultiple, object htmlAttributes)
GenerateSelect(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.String, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>, System.Collections.Generic.ICollection<System.String>, System.Boolean, System.Object)

Generate a <select> element for the <em>expression</em>.

Arguments:
Return type:

Microsoft.AspNetCore.Mvc.Rendering.TagBuilder

Returns:

A new Microsoft.AspNetCore.Mvc.Rendering.TagBuilder describing the <select> element.

TagBuilder GenerateSelect(ViewContext viewContext, ModelExplorer modelExplorer, string optionLabel, string expression, IEnumerable<SelectListItem> selectList, ICollection<string> currentValues, bool allowMultiple, object htmlAttributes)
GenerateTextArea(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Int32, System.Int32, System.Object)
Return type:Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
TagBuilder GenerateTextArea(ViewContext viewContext, ModelExplorer modelExplorer, string expression, int rows, int columns, object htmlAttributes)
GenerateTextBox(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Object, System.String, System.Object)
Return type:Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
TagBuilder GenerateTextBox(ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, string format, object htmlAttributes)
GenerateValidationMessage(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.String, System.String, System.Object)

Generate a <em>tag</em> element if the <em>viewContext</em>’s Microsoft.AspNetCore.Mvc.ActionContext.ModelState contains an error for the <em>expression</em>.

Arguments:
Return type:

Microsoft.AspNetCore.Mvc.Rendering.TagBuilder

Returns:

A Microsoft.AspNetCore.Mvc.Rendering.TagBuilder containing a <em>tag</em> element if the <em>viewContext</em>’s Microsoft.AspNetCore.Mvc.ActionContext.ModelState contains an error for the <em>expression</em> or (as a placeholder) if client-side validation is enabled. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.

TagBuilder GenerateValidationMessage(ViewContext viewContext, ModelExplorer modelExplorer, string expression, string message, string tag, object htmlAttributes)
GenerateValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, System.Boolean, System.String, System.String, System.Object)
Return type:Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
TagBuilder GenerateValidationSummary(ViewContext viewContext, bool excludePropertyErrors, string message, string headerTag, object htmlAttributes)
GetCurrentValues(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Boolean)

Gets the collection of current values for the given <em>expression</em>.

Arguments:
Return type:

System.Collections.Generic.ICollection<System.String>

Returns:

<p> <code>null</code> if no <em>expression</em> result is found. Otherwise a System.Collections.Generic.ICollection`1 containing current values for the given <em>expression</em>. </p> <p> Converts the <em>expression</em> result to a System.String. If that result is an System.Collections.IEnumerable type, instead converts each item in the collection and returns them separately. </p> <p> If the <em>expression</em> result or the element type is an System.Enum, returns a System.String containing the integer representation of the System.Enum value as well as all System.Enum names for that value. Otherwise returns the default System.String conversion of the value. </p>

ICollection<string> GetCurrentValues(ViewContext viewContext, ModelExplorer modelExplorer, string expression, bool allowMultiple)

Properties

Microsoft.AspNetCore.Mvc.ViewFeatures.IHtmlGenerator.IdAttributeDotReplacement
Return type:System.String
string IdAttributeDotReplacement { get; }