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)
-
GenerateActionLink
(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, System.String, System.String, System.String, System.String, System.String, System.String, System.Object, System.Object)¶ 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 theSystem.Object
. ThisSystem.Object
is typically created usingSystem.Object
initializer syntax. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the route parameters. - 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
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)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – The
-
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: - viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – The
Microsoft.AspNetCore.Mvc.Rendering.ViewContext
instance for the current scope. - modelExplorer (Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer) – The
Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
for the <em>expression</em>. - expression (System.String) – Expression name, relative to the current model.
- isChecked (System.Nullable<System.Boolean>) – The initial state of the checkbox 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
Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
instance for the <input type=”checkbox”.../> element.TagBuilder GenerateCheckBox(ViewContext viewContext, ModelExplorer modelExplorer, string expression, bool ? isChecked, object htmlAttributes)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – The
-
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 theSystem.Object
. ThisSystem.Object
is typically created usingSystem.Object
initializer syntax. Alternatively, anSystem.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, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: 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)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
-
GenerateGroupsAndOptions
(System.String, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>)¶ Generates <optgroup> and <option> elements.
Arguments: - optionLabel (System.String) – Optional text for a default empty <option> element.
- selectList (System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>) – A collection of
Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
objects used to generate <optgroup> and <option> elements.
Return type: 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 theSystem.Object
. ThisSystem.Object
is typically created usingSystem.Object
initializer syntax. Alternatively, anSystem.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, anSystem.Collections.Generic.IDictionary`2
instance containing the HTML attributes.
Return type: Returns: A
Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
instance for the </form> element.TagBuilder GenerateRouteForm(ViewContext viewContext, string routeName, object routeValues, string method, object htmlAttributes)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
-
GenerateRouteLink
(Microsoft.AspNetCore.Mvc.Rendering.ViewContext, System.String, System.String, System.String, System.String, System.String, System.Object, System.Object)¶ 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 theSystem.Object
. ThisSystem.Object
is typically created usingSystem.Object
initializer syntax. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the route parameters. - 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
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)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – The
-
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: - viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
Microsoft.AspNetCore.Mvc.Rendering.ViewContext
instance for the current scope. - modelExplorer (Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer) –
Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
for the <em>expression</em>. If <code>null</code>, determines validation attributes using <em>viewContext</em> and the <em>expression</em>. - optionLabel (System.String) – Optional text for a default empty <option> element.
- expression (System.String) – Expression name, relative to 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. If <code>null</code>, finds this collection at <code>ViewContext.ViewData[expression]</code>. - allowMultiple (System.Boolean) – If <code>true</code>, includes a <code>multiple</code> attribute in the generated HTML. Otherwise generates a single-selection <select> element.
- 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.Mvc.Rendering.TagBuilder
describing the <select> element.TagBuilder GenerateSelect(ViewContext viewContext, ModelExplorer modelExplorer, string optionLabel, string expression, IEnumerable<SelectListItem> selectList, bool allowMultiple, object htmlAttributes)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
-
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: - viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
Microsoft.AspNetCore.Mvc.Rendering.ViewContext
instance for the current scope. - modelExplorer (Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer) –
Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
for the <em>expression</em>. If <code>null</code>, determines validation attributes using <em>viewContext</em> and the <em>expression</em>. - optionLabel (System.String) – Optional text for a default empty <option> element.
- expression (System.String) – Expression name, relative to 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. If <code>null</code>, finds this collection at <code>ViewContext.ViewData[expression]</code>. - currentValues (System.Collections.Generic.ICollection<System.String>) – An
System.Collections.Generic.ICollection`1
containing values for <option> elements to select. If <code>null</code>, selects <option> elements based onMicrosoft.AspNetCore.Mvc.Rendering.SelectListItem.Selected
values in <em>selectList</em>. - allowMultiple (System.Boolean) – If <code>true</code>, includes a <code>multiple</code> attribute in the generated HTML. Otherwise generates a single-selection <select> element.
- 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.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)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
-
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: - viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
Microsoft.AspNetCore.Mvc.Rendering.ViewContext
instance for the current scope. - modelExplorer (Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer) – The
Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
for the <em>expression</em>. - expression (System.String) – Expression name, relative to 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. - 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
. - 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
Microsoft.AspNetCore.Mvc.Rendering.TagBuilder
containing a <em>tag</em> element if the <em>viewContext</em>’sMicrosoft.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)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
-
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: - viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
Microsoft.AspNetCore.Mvc.Rendering.ViewContext
instance for the current scope. - modelExplorer (Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer) –
Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
for the <em>expression</em>. If <code>null</code>, calculates the <em>expression</em> result usingMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Eval(System.String)
. - expression (System.String) – Expression name, relative to the current model.
- allowMultiple (System.Boolean) – If <code>true</code>, require a collection <em>expression</em> result. Otherwise, treat result as a single value.
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 aSystem.String
. If that result is anSystem.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 anSystem.Enum
, returns aSystem.String
containing the integer representation of theSystem.Enum
value as well as allSystem.Enum
names for that value. Otherwise returns the defaultSystem.String
conversion of the value. </p>ICollection<string> GetCurrentValues(ViewContext viewContext, ModelExplorer modelExplorer, string expression, bool allowMultiple)
- viewContext (Microsoft.AspNetCore.Mvc.Rendering.ViewContext) – A
-
Properties¶
-
Microsoft.AspNetCore.Mvc.ViewFeatures.IHtmlGenerator.
IdAttributeDotReplacement
¶ Return type: System.String string IdAttributeDotReplacement { get; }
-