HtmlHelper Class¶
Default implementation of Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper.
- Namespace
Microsoft.AspNetCore.Mvc.ViewFeatures- Assemblies
- Microsoft.AspNetCore.Mvc.ViewFeatures
Syntax¶
public class HtmlHelper : IHtmlHelper, IViewContextAware
-
class
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper
Constructors¶
-
HtmlHelper(Microsoft.AspNetCore.Mvc.ViewFeatures.IHtmlGenerator, Microsoft.AspNetCore.Mvc.ViewEngines.ICompositeViewEngine, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.IViewBufferScope, System.Text.Encodings.Web.HtmlEncoder, System.Text.Encodings.Web.UrlEncoder)¶ Initializes a new instance of the
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelperclass.public HtmlHelper(IHtmlGenerator htmlGenerator, ICompositeViewEngine viewEngine, IModelMetadataProvider metadataProvider, IViewBufferScope bufferScope, HtmlEncoder htmlEncoder, UrlEncoder urlEncoder)
-
Methods¶
-
ActionLink(System.String, System.String, System.String, System.String, System.String, System.String, System.Object, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent ActionLink(string linkText, string actionName, string controllerName, string protocol, string hostname, string fragment, object routeValues, object htmlAttributes)
-
AnonymousObjectToHtmlAttributes(System.Object)¶ Creates a dictionary of HTML attributes from the input object, translating underscores to dashes in each public instance property.
If the object is already an
System.Collections.Generic.IDictionary`2instance, then it is returned as-is. <example> <code>new { data_name=”value” }</code> will translate to the entry <code>{ “data-name”, “value” }</code> in the resulting dictionary. </example>Arguments: htmlAttributes (System.Object) – Anonymous object describing HTML attributes. Return type: System.Collections.Generic.IDictionary<System.String> Returns: A dictionary that represents HTML attributes. public static IDictionary<string, object> AnonymousObjectToHtmlAttributes(object htmlAttributes)
-
AntiForgeryToken()¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent AntiForgeryToken()
-
BeginForm(System.String, System.String, System.Object, Microsoft.AspNetCore.Mvc.Rendering.FormMethod, System.Nullable<System.Boolean>, System.Object)¶ Return type: Microsoft.AspNetCore.Mvc.Rendering.MvcForm public MvcForm BeginForm(string actionName, string controllerName, object routeValues, FormMethod method, bool ? antiforgery, object htmlAttributes)
-
BeginRouteForm(System.String, System.Object, Microsoft.AspNetCore.Mvc.Rendering.FormMethod, System.Nullable<System.Boolean>, System.Object)¶ Return type: Microsoft.AspNetCore.Mvc.Rendering.MvcForm public MvcForm BeginRouteForm(string routeName, object routeValues, FormMethod method, bool ? antiforgery, object htmlAttributes)
-
CheckBox(System.String, System.Nullable<System.Boolean>, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent CheckBox(string expression, bool ? isChecked, object htmlAttributes)
-
Contextualize(Microsoft.AspNetCore.Mvc.Rendering.ViewContext)¶ public virtual void Contextualize(ViewContext viewContext)
-
CreateForm()¶ Override this method to return an
Microsoft.AspNetCore.Mvc.Rendering.MvcFormsubclass. That subclass may changeMicrosoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.EndFormbehavior.Return type: Microsoft.AspNetCore.Mvc.Rendering.MvcForm Returns: A new Microsoft.AspNetCore.Mvc.Rendering.MvcForminstance.protected virtual MvcForm CreateForm()
-
Display(System.String, System.String, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent Display(string expression, string templateName, string htmlFieldName, object additionalViewData)
-
DisplayName(System.String)¶ Return type: System.String public string DisplayName(string expression)
-
DisplayText(System.String)¶ Return type: System.String public string DisplayText(string expression)
-
DropDownList(System.String, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent DropDownList(string expression, IEnumerable<SelectListItem> selectList, string optionLabel, object htmlAttributes)
-
Editor(System.String, System.String, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent Editor(string expression, string templateName, string htmlFieldName, object additionalViewData)
-
Encode(System.Object)¶ Return type: System.String public string Encode(object value)
-
Encode(System.String) Return type: System.String public string Encode(string value)
-
EndForm()¶ public void EndForm()
-
FormatValue(System.Object, System.String)¶ Return type: System.String public string FormatValue(object value, string format)
-
GenerateCheckBox(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Nullable<System.Boolean>, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateCheckBox(ModelExplorer modelExplorer, string expression, bool ? isChecked, object htmlAttributes)
-
GenerateDisplay(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateDisplay(ModelExplorer modelExplorer, string htmlFieldName, string templateName, object additionalViewData)
-
GenerateDisplayName(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String)¶ Return type: System.String protected virtual string GenerateDisplayName(ModelExplorer modelExplorer, string expression)
-
GenerateDisplayText(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer)¶ Return type: System.String protected virtual string GenerateDisplayText(ModelExplorer modelExplorer)
-
GenerateDropDown(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected IHtmlContent GenerateDropDown(ModelExplorer modelExplorer, string expression, IEnumerable<SelectListItem> selectList, string optionLabel, object htmlAttributes)
-
GenerateEditor(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateEditor(ModelExplorer modelExplorer, string htmlFieldName, string templateName, object additionalViewData)
-
GenerateForm(System.String, System.String, System.Object, Microsoft.AspNetCore.Mvc.Rendering.FormMethod, System.Nullable<System.Boolean>, System.Object)¶ Renders a <form> start tag to the response. When the user submits the form, the action with name <em>actionName</em> will process the request.
Arguments: - actionName (System.String) – The name of the action method.
- controllerName (System.String) – The name of the controller.
- routeValues (System.Object) – An
System.Objectthat contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of theSystem.Object. ThisSystem.Objectis typically created usingSystem.Objectinitializer syntax. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the route parameters. - method (Microsoft.AspNetCore.Mvc.Rendering.FormMethod) – The HTTP method for processing the form, either GET or POST.
- antiforgery (System.Nullable<System.Boolean>) – If <code>true</code>, <form> elements will include an antiforgery token.
If <code>false</code>, suppresses the generation an <input> of type “hidden” with an antiforgery token.
If <code>null</code>, <form> elements will include an antiforgery token only if
<em>method</em> is not
Microsoft.AspNetCore.Mvc.Rendering.FormMethod.Get. - htmlAttributes (System.Object) – An
System.Objectthat contains the HTML attributes for the element. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the HTML attributes.
Return type: Returns: An
Microsoft.AspNetCore.Mvc.Rendering.MvcForminstance which renders the </form> end tag when disposed.protected virtual MvcForm GenerateForm(string actionName, string controllerName, object routeValues, FormMethod method, bool ? antiforgery, object htmlAttributes)
-
GenerateHidden(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Object, System.Boolean, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateHidden(ModelExplorer modelExplorer, string expression, object value, bool useViewData, object htmlAttributes)
-
GenerateId(System.String)¶ Return type: System.String protected virtual string GenerateId(string expression)
-
GenerateIdFromName(System.String)¶ Return type: System.String public string GenerateIdFromName(string fullName)
-
GenerateLabel(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateLabel(ModelExplorer modelExplorer, string expression, string labelText, object htmlAttributes)
-
GenerateListBox(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected IHtmlContent GenerateListBox(ModelExplorer modelExplorer, string expression, IEnumerable<SelectListItem> selectList, object htmlAttributes)
-
GenerateName(System.String)¶ Return type: System.String protected virtual string GenerateName(string expression)
-
GeneratePassword(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Object, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GeneratePassword(ModelExplorer modelExplorer, string expression, object value, object htmlAttributes)
-
GenerateRadioButton(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Object, System.Nullable<System.Boolean>, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateRadioButton(ModelExplorer modelExplorer, string expression, object value, bool ? isChecked, object htmlAttributes)
-
GenerateRouteForm(System.String, System.Object, Microsoft.AspNetCore.Mvc.Rendering.FormMethod, System.Nullable<System.Boolean>, System.Object)¶ Renders a <form> start tag to the response. The route with name <em>routeName</em> generates the <form>’s <code>action</code> attribute value.
Arguments: - routeName (System.String) – The name of the route.
- routeValues (System.Object) – An
System.Objectthat contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of theSystem.Object. ThisSystem.Objectis typically created usingSystem.Objectinitializer syntax. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the route parameters. - method (Microsoft.AspNetCore.Mvc.Rendering.FormMethod) – The HTTP method for processing the form, either GET or POST.
- antiforgery (System.Nullable<System.Boolean>) – If <code>true</code>, <form> elements will include an antiforgery token.
If <code>false</code>, suppresses the generation an <input> of type “hidden” with an antiforgery token.
If <code>null</code>, <form> elements will include an antiforgery token only if
<em>method</em> is not
Microsoft.AspNetCore.Mvc.Rendering.FormMethod.Get. - htmlAttributes (System.Object) – An
System.Objectthat contains the HTML attributes for the element. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the HTML attributes.
Return type: Returns: An
Microsoft.AspNetCore.Mvc.Rendering.MvcForminstance which renders the </form> end tag when disposed.protected virtual MvcForm GenerateRouteForm(string routeName, object routeValues, FormMethod method, bool ? antiforgery, object htmlAttributes)
-
GenerateTextArea(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Int32, System.Int32, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateTextArea(ModelExplorer modelExplorer, string expression, int rows, int columns, object htmlAttributes)
-
GenerateTextBox(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.Object, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateTextBox(ModelExplorer modelExplorer, string expression, object value, string format, object htmlAttributes)
-
GenerateValidationMessage(Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer, System.String, System.String, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateValidationMessage(ModelExplorer modelExplorer, string expression, string message, string tag, object htmlAttributes)
-
GenerateValidationSummary(System.Boolean, System.String, System.Object, System.String)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent protected virtual IHtmlContent GenerateValidationSummary(bool excludePropertyErrors, string message, object htmlAttributes, string tag)
-
GenerateValue(System.String, System.Object, System.String, System.Boolean)¶ Return type: System.String protected virtual string GenerateValue(string expression, object value, string format, bool useViewData)
-
GetEnumSelectList(Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata)¶ Returns a select list for the given <em>metadata</em>.
Arguments: metadata (Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata) – Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadatato generate a select list for.Return type: System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> Returns: An System.Collections.Generic.IEnumerable`1containing the select list for the given <em>metadata</em>.protected virtual IEnumerable<SelectListItem> GetEnumSelectList(ModelMetadata metadata)
-
GetEnumSelectList(System.Type) Return type: System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> public IEnumerable<SelectListItem> GetEnumSelectList(Type enumType)
-
GetEnumSelectList<TEnum>()¶ Return type: System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> public IEnumerable<SelectListItem> GetEnumSelectList<TEnum>()where TEnum : struct
-
GetFormMethodString(Microsoft.AspNetCore.Mvc.Rendering.FormMethod)¶ Returns the HTTP method that handles form input (GET or POST) as a string.
Arguments: method (Microsoft.AspNetCore.Mvc.Rendering.FormMethod) – The HTTP method that handles the form. Return type: System.String Returns: The form method string, either “get” or “post”. public static string GetFormMethodString(FormMethod method)
-
Hidden(System.String, System.Object, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent Hidden(string expression, object value, object htmlAttributes)
-
Id(System.String)¶ Return type: System.String public string Id(string expression)
-
Label(System.String, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent Label(string expression, string labelText, object htmlAttributes)
-
ListBox(System.String, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent ListBox(string expression, IEnumerable<SelectListItem> selectList, object htmlAttributes)
-
Name(System.String)¶ Return type: System.String public string Name(string expression)
-
ObjectToDictionary(System.Object)¶ Creates a dictionary from an object, by adding each public instance property as a key with its associated value to the dictionary. It will expose public properties from derived types as well. This is typically used with objects of an anonymous type.
If the <em>value</em> is already an
System.Collections.Generic.IDictionary`2instance, then it is returned as-is. <example> <code>new { data_name=”value” }</code> will translate to the entry <code>{ “data_name”, “value” }</code> in the resulting dictionary. </example>Arguments: value (System.Object) – The System.Objectto be converted.Return type: System.Collections.Generic.IDictionary<System.String> Returns: The created dictionary of property names and property values. public static IDictionary<string, object> ObjectToDictionary(object value)
-
PartialAsync(System.String, System.Object, Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)¶ Return type: System.Threading.Tasks.Task<Microsoft.AspNetCore.Html.IHtmlContent> public Task<IHtmlContent> PartialAsync(string partialViewName, object model, ViewDataDictionary viewData)
-
Password(System.String, System.Object, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent Password(string expression, object value, object htmlAttributes)
-
RadioButton(System.String, System.Object, System.Nullable<System.Boolean>, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent RadioButton(string expression, object value, bool ? isChecked, object htmlAttributes)
-
Raw(System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent Raw(object value)
-
Raw(System.String) Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent Raw(string value)
-
RenderPartialAsync(System.String, System.Object, Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)¶ Return type: System.Threading.Tasks.Task public Task RenderPartialAsync(string partialViewName, object model, ViewDataDictionary viewData)
-
RenderPartialCoreAsync(System.String, System.Object, Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary, System.IO.TextWriter)¶ Return type: System.Threading.Tasks.Task protected virtual Task RenderPartialCoreAsync(string partialViewName, object model, ViewDataDictionary viewData, TextWriter writer)
-
RouteLink(System.String, System.String, System.String, System.String, System.String, System.Object, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent RouteLink(string linkText, string routeName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)
-
TextArea(System.String, System.String, System.Int32, System.Int32, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent TextArea(string expression, string value, int rows, int columns, object htmlAttributes)
-
TextBox(System.String, System.Object, System.String, System.Object)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent TextBox(string expression, object value, string format, object htmlAttributes)
-
ValidationMessage(System.String, System.String, System.Object, System.String)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent ValidationMessage(string expression, string message, object htmlAttributes, string tag)
-
ValidationSummary(System.Boolean, System.String, System.Object, System.String)¶ Return type: Microsoft.AspNetCore.Html.IHtmlContent public IHtmlContent ValidationSummary(bool excludePropertyErrors, string message, object htmlAttributes, string tag)
-
Value(System.String, System.String)¶ Return type: System.String public string Value(string expression, string format)
-
Fields¶
-
ValidationInputCssClassName()¶ Return type: System.String public static readonly string ValidationInputCssClassName
-
ValidationInputValidCssClassName()¶ Return type: System.String public static readonly string ValidationInputValidCssClassName
-
ValidationMessageCssClassName()¶ Return type: System.String public static readonly string ValidationMessageCssClassName
-
ValidationMessageValidCssClassName()¶ Return type: System.String public static readonly string ValidationMessageValidCssClassName
-
ValidationSummaryCssClassName()¶ Return type: System.String public static readonly string ValidationSummaryCssClassName
-
ValidationSummaryValidCssClassName()¶ Return type: System.String public static readonly string ValidationSummaryValidCssClassName
-
Properties¶
-
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.Html5DateRenderingMode¶ Return type: Microsoft.AspNetCore.Mvc.Rendering.Html5DateRenderingMode public Html5DateRenderingMode Html5DateRenderingMode { get; set; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.IdAttributeDotReplacement¶ Return type: System.String public string IdAttributeDotReplacement { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.MetadataProvider¶ Return type: Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider public IModelMetadataProvider MetadataProvider { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.TempData¶ Return type: Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionary public ITempDataDictionary TempData { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.UrlEncoder¶ Return type: System.Text.Encodings.Web.UrlEncoder public UrlEncoder UrlEncoder { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.ViewBag¶ Return type: System.Object public dynamic ViewBag { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.ViewContext¶ Return type: Microsoft.AspNetCore.Mvc.Rendering.ViewContext public ViewContext ViewContext { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.ViewData¶ Return type: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary public ViewDataDictionary ViewData { get; }
-