// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.WebEncoders;
namespace Microsoft.AspNet.Mvc.Rendering
{
///
/// Base HTML helpers.
///
public interface IHtmlHelper
{
///
/// Set this property to to have templated helpers such as
/// and render date and time values as RFC
/// 3339 compliant strings. By default these helpers render dates and times using the current culture.
///
Html5DateRenderingMode Html5DateRenderingMode { get; set; }
///
/// Gets the that replaces periods in the ID attribute of an element.
///
string IdAttributeDotReplacement { get; }
///
/// Gets the metadata provider. Intended for use in extension methods.
///
IModelMetadataProvider MetadataProvider { get; }
///
/// Gets the view bag.
///
dynamic ViewBag { get; }
///
/// Gets the context information about the view.
///
ViewContext ViewContext { get; }
///
/// Gets the current view data.
///
ViewDataDictionary ViewData { get; }
///
/// Gets the current instance.
///
ITempDataDictionary TempData { get; }
///
/// Gets the to be used for encoding a URL.
///
IUrlEncoder UrlEncoder { get; }
///
/// Gets the to be used for encoding JavaScript.
///
IJavaScriptStringEncoder JavaScriptStringEncoder { get; }
///
/// Returns an anchor (<a>) element that contains a URL path to the specified action.
///
/// The inner text of the anchor element. Must not be null.
/// The name of the action.
/// The name of the controller.
/// The protocol for the URL, such as "http" or "https".
/// The host name for the URL.
/// The URL fragment name (the anchor name).
///
/// An that contains the parameters for a route. The parameters are retrieved through
/// reflection by examining the properties of the . This is typically
/// created using initializer syntax. Alternatively, an
/// instance containing the route parameters.
///
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the anchor element.
IHtmlContent ActionLink(
string linkText,
string actionName,
string controllerName,
string protocol,
string hostname,
string fragment,
object routeValues,
object htmlAttributes);
///
/// Returns a <hidden> element (antiforgery token) that will be validated when the containing
/// <form> is submitted.
///
/// containing the <hidden> element.
IHtmlContent AntiForgeryToken();
///
/// Renders a <form> start tag to the response. When the user submits the form, the action with name
/// will process the request.
///
/// The name of the action method.
/// The name of the controller.
///
/// An that contains the parameters for a route. The parameters are retrieved through
/// reflection by examining the properties of the . This is typically
/// created using initializer syntax. Alternatively, an
/// instance containing the route parameters.
///
/// The HTTP method for processing the form, either GET or POST.
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
///
/// An instance which renders the </form> end tag when disposed.
///
///
/// In this context, "renders" means the method writes its output using .
///
MvcForm BeginForm(
string actionName,
string controllerName,
object routeValues,
FormMethod method,
object htmlAttributes);
///
/// Renders a <form> start tag to the response. The route with name
/// generates the <form>'s action attribute value.
///
/// The name of the route.
///
/// An that contains the parameters for a route. The parameters are retrieved through
/// reflection by examining the properties of the . This is typically
/// created using initializer syntax. Alternatively, an
/// instance containing the route parameters.
///
/// The HTTP method for processing the form, either GET or POST.
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
///
/// An instance which renders the </form> end tag when disposed.
///
///
/// In this context, "renders" means the method writes its output using .
///
MvcForm BeginRouteForm(
string routeName,
object routeValues,
FormMethod method,
object htmlAttributes);
///
/// Returns an <input> element of type "checkbox" with value "true" and an <input> element of type
/// "hidden" with value "false".
///
/// Expression name, relative to the current model.
/// If true, checkbox is initially checked.
///
/// An that contains the HTML attributes for the checkbox element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <input> elements.
///
///
/// Combines and to set checkbox
/// element's "name" attribute. Sanitizes to set checkbox element's "id"
/// attribute.
///
/// Determines checkbox element's "checked" attribute based on the following precedence:
///
/// -
/// entry for (converted to a fully-qualified
/// name) if entry exists and can be converted to a .
///
/// - if non-null.
/// -
/// entry for (converted to a fully-qualified name)
/// if entry exists and can be converted to a .
///
/// -
/// Linq expression based on (converted to a fully-qualified name) run against
/// current model if result is non-null and can be converted to a . For example
/// string.Empty identifies the current model and "prop" identifies the current model's "prop"
/// property.
///
/// - Existing "checked" entry in if any.
/// - Otherwise, does not include a "checked" attribute.
///
///
/// In all but the and default cases, includes a "checked" attribute with
/// value "checked" if the values is true; does not include the attribute otherwise.
///
///
IHtmlContent CheckBox(string expression, bool? isChecked, object htmlAttributes);
///
/// Returns HTML markup for the , using a display template, specified HTML field
/// name, and additional view data. The template is found using the or the
/// 's .
///
///
/// Expression name, relative to the current model. May identify a single property or an
/// that contains the properties to display.
///
/// The name of the template used to create the HTML markup.
///
/// A used to disambiguate the names of HTML elements that are created for
/// properties that have the same name.
///
///
/// An anonymous or that can contain additional
/// view data that will be merged into the instance created for the
/// template.
///
/// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
/// 's value.
///
///
/// Example s include string.Empty which identifies the current model and
/// "prop" which identifies the current model's "prop" property.
///
///
IHtmlContent Display(
string expression,
string templateName,
string htmlFieldName,
object additionalViewData);
///
/// Returns the display name for the specified .
///
/// Expression name, relative to the current model.
/// A containing the display name.
string DisplayName(string expression);
///
/// Returns the simple display text for the specified .
///
/// Expression name, relative to the current model.
///
/// A containing the simple display text.
/// If the expression result is null, returns .
///
string DisplayText(string expression);
///
/// Returns a single-selection HTML <select> element for the ,
/// using the specified list items, option label, and HTML attributes.
///
/// Expression name, relative to the current model.
///
/// A collection of objects used to populate the <select> element with
/// <optgroup> and <option> elements.
///
///
/// The text for a default empty item. Does not include such an item if argument is null.
///
///
/// An that contains the HTML attributes for the <select> element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
IHtmlContent DropDownList(
string expression,
IEnumerable selectList,
string optionLabel,
object htmlAttributes);
///
/// Returns HTML markup for the , using an editor template, specified HTML field
/// name, and additional view data. The template is found using the or the
/// 's .
///
///
/// Expression name, relative to the current model. May identify a single property or an
/// that contains the properties to edit.
///
/// The name of the template used to create the HTML markup.
///
/// A used to disambiguate the names of HTML elements that are created for
/// properties that have the same name.
///
///
/// An anonymous or that can contain additional
/// view data that will be merged into the instance created for the
/// template.
///
/// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
/// elements for each property in the 's value.
///
///
/// Example s include string.Empty which identifies the current model and
/// "prop" which identifies the current model's "prop" property.
///
///
IHtmlContent Editor(string expression, string templateName, string htmlFieldName, object additionalViewData);
///
/// Converts the to an HTML-encoded .
///
/// The to encode.
/// The HTML-encoded .
string Encode(object value);
///
/// Converts the specified to an HTML-encoded .
///
/// The to encode.
/// The HTML-encoded .
string Encode(string value);
///
/// Renders the </form> end tag to the response.
///
///
/// In this context, "renders" means the method writes its output using .
///
void EndForm();
///
/// Formats the value.
///
/// The value.
///
/// The composite format (see http://msdn.microsoft.com/en-us/library/txafckwd.aspx).
///
/// A containing the formatted value.
///
/// Converts to a directly if
/// is null or empty.
///
string FormatValue(object value, string format);
///
/// Returns an HTML element Id for the specified expression .
///
///
/// Fully-qualified expression name, ignoring the current model. Must not be null.
///
/// A containing the element Id.
string GenerateIdFromName(string fullName);
///
/// Returns information about about client validation rules for the specified or
/// . Intended for use in extension methods.
///
/// Metadata about the of interest.
///
/// Expression name, relative to the current model. Used to determine when
/// is null; ignored otherwise.
///
/// An containing the relevant rules.
IEnumerable GetClientValidationRules(
ModelExplorer modelExplorer,
string expression);
///
/// Returns a select list for the given .
///
/// Type to generate a select list for.
///
/// An containing the select list for the given
/// .
///
///
/// Thrown if is not an or if it has a
/// .
///
IEnumerable GetEnumSelectList() where TEnum : struct;
///
/// Returns a select list for the given .
///
/// to generate a select list for.
///
/// An containing the select list for the given
/// .
///
///
/// Thrown if is not an or if it has a
/// .
///
IEnumerable GetEnumSelectList(Type enumType);
///
/// Returns an <input> element of type "hidden" for the specified .
///
/// Expression name, relative to the current model.
/// If non-null, value to include in the element.
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <input> element.
///
///
/// Combines and to set
/// <input> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
/// Determines <input> element's "value" attribute based on the following precedence:
///
/// -
/// entry for (converted to a fully-qualified
/// name) if entry exists and can be converted to a .
///
/// - if non-null.
/// -
/// entry for (converted to a fully-qualified name)
/// if entry exists and can be converted to a .
///
/// -
/// Linq expression based on (converted to a fully-qualified name) run against
/// current model if result is non-null and can be converted to a . For example
/// string.Empty identifies the current model and "prop" identifies the current model's "prop"
/// property.
///
/// - Existing "value" entry in if any.
/// - Otherwise, string.Empty.
///
///
IHtmlContent Hidden(string expression, object value, object htmlAttributes);
///
/// Returns the HTML element Id for the specified .
///
/// Expression name, relative to the current model.
/// A containing the element Id.
string Id(string expression);
///
/// Returns a <label> element for the specified .
///
/// Expression name, relative to the current model.
/// The inner text of the element.
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <label> element.
IHtmlContent Label(string expression, string labelText, object htmlAttributes);
///
/// Returns a multi-selection <select> element for the , using the
/// specified list items and HTML attributes.
///
/// Expression name, relative to the current model.
///
/// A collection of objects used to populate the <select> element with
/// <optgroup> and <option> elements.
///
///
/// An that contains the HTML attributes for the <select> element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
IHtmlContent ListBox(string expression, IEnumerable selectList, object htmlAttributes);
///
/// Returns the full HTML element name for the specified .
///
/// Expression name, relative to the current model.
/// A containing the element name.
string Name(string expression);
///
/// Returns HTML markup for the specified partial view.
///
///
/// The name of the partial view used to create the HTML markup. Must not be null.
///
/// A model to pass into the partial view.
/// A to pass into the partial view.
///
/// A that on completion returns a new containing
/// the created HTML.
///
Task PartialAsync(string partialViewName, object model, ViewDataDictionary viewData);
///
/// Returns an <input> element of type "password" for the specified .
///
/// Expression name, relative to the current model.
/// If non-null, value to include in the element.
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <input> element.
///
///
/// Combines and to set
/// <input> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
/// Determines <input> element's "value" attribute based on the following precedence:
///
/// - if non-null.
/// - Existing "value" entry in if any.
/// - Otherwise, string.Empty.
///
///
IHtmlContent Password(string expression, object value, object htmlAttributes);
///
/// Returns an <input> element of type "radio" for the specified .
///
/// Expression name, relative to the current model.
///
/// If non-null, value to include in the element. Must not be null if
/// is also null and no "checked" entry exists in
/// .
///
///
/// If true, radio button is initially selected. Must not be null if
/// is also null and no "checked" entry exists in
/// .
///
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <input> element.
///
///
/// Combines and to set
/// <input> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
/// Determines element's "value" attribute based on the following precedence:
///
/// - if non-null.
/// - Existing "value" entry in if any.
/// - Otherwise, string.Empty.
///
/// Determines <input> element's "checked" attribute based on the following precedence:
///
/// -
/// entry for (converted to a fully-qualified
/// name) if entry exists and can be converted to a .
///
/// - if non-null.
/// - Existing "checked" entry in if any.
/// -
/// entry for (converted to a fully-qualified name)
/// if entry exists and can be converted to a .
///
/// -
/// Linq expression based on (converted to a fully-qualified name) run against
/// current model if result is non-null and can be converted to a . For example
/// string.Empty identifies the current model and "prop" identifies the current model's "prop"
/// property.
///
/// - Otherwise, does not include a "checked" attribute.
///
///
/// In all but the and default cases, includes a "checked" attribute with
/// value "checked" if the values is equal to a converted for
/// or is true (for that case); does not include
/// the attribute otherwise.
///
///
IHtmlContent RadioButton(string expression, object value, bool? isChecked, object htmlAttributes);
///
/// Wraps HTML markup in an , without HTML-encoding the specified
/// .
///
/// HTML markup .
/// A new containing the wrapped .
IHtmlContent Raw(string value);
///
/// Wraps HTML markup from the string representation of an in an
/// , without HTML-encoding the string representation.
///
/// The to wrap.
/// containing the wrapped string representation.
IHtmlContent Raw(object value);
///
/// Renders HTML markup for the specified partial view.
///
///
/// The name of the partial view used to create the HTML markup. Must not be null.
///
/// A model to pass into the partial view.
/// A to pass into the partial view.
/// A that renders the created HTML when it executes.
///
/// In this context, "renders" means the method writes its output using .
///
Task RenderPartialAsync(string partialViewName, object model, ViewDataDictionary viewData);
///
/// Returns an anchor (<a>) element that contains a URL path to the specified route.
///
/// The inner text of the anchor element. Must not be null.
/// The name of the route.
/// The protocol for the URL, such as "http" or "https".
/// The host name for the URL.
/// The URL fragment name (the anchor name).
///
/// An that contains the parameters for a route. The parameters are retrieved through
/// reflection by examining the properties of the . This is typically
/// created using initializer syntax. Alternatively, an
/// instance containing the route parameters.
///
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the anchor element.
IHtmlContent RouteLink(
string linkText,
string routeName,
string protocol,
string hostName,
string fragment,
object routeValues,
object htmlAttributes);
///
/// Returns a <textarea> element for the specified .
///
/// Expression name, relative to the current model.
/// If non-null, value to include in the element.
/// Number of rows in the textarea.
/// Number of columns in the textarea.
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <textarea> element.
///
///
/// Combines and to set
/// <textarea> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
/// Determines <textarea> element's content based on the following precedence:
///
/// -
/// entry for (converted to a fully-qualified
/// name) if entry exists and can be converted to a .
///
/// - if non-null.
/// -
/// entry for (converted to a fully-qualified name)
/// if entry exists and can be converted to a .
///
/// -
/// Linq expression based on (converted to a fully-qualified name) run against
/// current model if result is non-null and can be converted to a . For example
/// string.Empty identifies the current model and "prop" identifies the current model's "prop"
/// property.
///
/// - Otherwise, string.Empty.
///
///
IHtmlContent TextArea(string expression, string value, int rows, int columns, object htmlAttributes);
///
/// Returns an <input> element of type "text" for the specified .
///
/// Expression name, relative to the current model.
/// If non-null, value to include in the element.
///
/// The composite format (see http://msdn.microsoft.com/en-us/library/txafckwd.aspx).
///
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new containing the <input> element.
///
///
/// Combines and to set
/// <input> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
/// Determines <input> element's "value" attribute based on the following precedence:
///
/// -
/// entry for (converted to a fully-qualified
/// name) if entry exists and can be converted to a .
///
/// -
/// if non-null. Formats using
/// or converts to a directly if
/// is null or empty.
///
/// -
/// entry for (converted to a fully-qualified name) if entry
/// exists and can be converted to a . Formats entry using or
/// converts entry to a directly if is null or empty.
///
/// -
/// Linq expression based on (converted to a fully-qualified name) run against
/// current model if result is non-null and can be converted to a . For example
/// string.Empty identifies the current model and "prop" identifies the current model's "prop"
/// property. Formats result using or converts result to a
/// directly if is null or empty.
///
/// - Existing "value" entry in if any.
/// - Otherwise, string.Empty.
///
///
IHtmlContent TextBox(string current, object value, string format, object htmlAttributes);
///
/// Returns the validation message if an error exists in the object
/// for the specified .
///
/// Expression name, relative to the current model.
///
/// The message to be displayed. If null or empty, method extracts an error string from the
/// object. Message will always be visible but client-side validation may
/// update the associated CSS class.
///
///
/// An that contains the HTML attributes for the element.
/// Alternatively, an instance containing the HTML attributes.
///
///
/// The tag to wrap the in the generated HTML. Its default value is
/// .
///
///
/// A new containing a element. null if the
/// is valid and client-side validation is disabled.
///
IHtmlContent ValidationMessage(string expression, string message, object htmlAttributes, string tag);
///
/// Returns an unordered list (<ul> element) of validation messages that are in the
/// object.
///
///
/// If true, display model-level errors only; otherwise display all errors.
///
/// The message to display with the validation summary.
///
/// An that contains the HTML attributes for the topmost (<div>) element.
/// Alternatively, an instance containing the HTML attributes.
///
///
/// The tag to wrap the in the generated HTML. Its default value is
/// .
///
///
/// New containing a <div> element wrapping the element
/// and the <ul> element. if the current model is valid and client-side
/// validation is disabled).
///
IHtmlContent ValidationSummary(
bool excludePropertyErrors,
string message,
object htmlAttributes,
string tag);
///
/// Returns the formatted value for the specified .
///
/// Expression name, relative to the current model.
///
/// The composite format (see http://msdn.microsoft.com/en-us/library/txafckwd.aspx).
///
/// A containing the formatted value.
///
/// Converts the expression result to a directly if
/// is null or empty.
///
string Value(string expression, string format);
}
}