// 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.Collections.Generic;
using Microsoft.AspNet.Html;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
///
/// Contract for a service supporting and ITagHelper implementations.
///
public interface IHtmlGenerator
{
string IdAttributeDotReplacement { get; }
string Encode(string value);
string Encode(object value);
string FormatValue(object value, string format);
///
/// Generate a <a> element for a link to an action.
///
/// The instance for the current scope.
/// The text to insert inside the element.
/// The name of the action method.
/// The name of the controller.
/// The protocol (scheme) for the generated link.
/// The hostname for the generated link.
/// The fragment for the genrated link.
///
/// 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 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);
///
/// Generate an <input type="hidden".../> element containing an antiforgery token.
///
/// The instance for the current scope.
///
/// An instance for the <input type="hidden".../> element. Intended to be used
/// inside a <form> element.
///
IHtmlContent GenerateAntiforgery(ViewContext viewContext);
///
/// Generate a <input type="checkbox".../> element.
///
/// The instance for the current scope.
/// The for the model.
/// The model expression.
/// The initial state of the checkbox element.
///
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
///
/// A instance for the <input type="checkbox".../> element.
///
TagBuilder GenerateCheckBox(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
bool? isChecked,
object htmlAttributes);
///
/// 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.
///
TagBuilder GenerateHiddenForCheckbox(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression);
///
/// Generate a <form> element. When the user submits the form, the action with name
/// will process the request.
///
/// A instance for the current scope.
/// 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.
///
///
/// A instance for the </form> element.
///
TagBuilder GenerateForm(
ViewContext viewContext,
string actionName,
string controllerName,
object routeValues,
string method,
object htmlAttributes);
///
/// Generate a <form> element. The route with name generates the
/// <form>'s action attribute value.
///
/// A instance for the current scope.
/// 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.
///
///
/// A instance for the </form> element.
///
TagBuilder GenerateRouteForm(
ViewContext viewContext,
string routeName,
object routeValues,
string method,
object htmlAttributes);
TagBuilder GenerateHidden(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
bool useViewData,
object htmlAttributes);
TagBuilder GenerateLabel(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
string labelText,
object htmlAttributes);
TagBuilder GeneratePassword(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
object htmlAttributes);
TagBuilder GenerateRadioButton(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
bool? isChecked,
object htmlAttributes);
///
/// Generate a <a> element for a link to an action.
///
/// The instance for the current scope.
/// The text to insert inside the element.
/// The name of the route to use for link generation.
/// The protocol (scheme) for the generated link.
/// The hostname for the generated link.
/// The fragment for the genrated link.
///
/// 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 instance for the <a> element.
///
TagBuilder GenerateRouteLink(
ViewContext viewContext,
string linkText,
string routeName,
string protocol,
string hostName,
string fragment,
object routeValues,
object htmlAttributes);
///
/// Generate a <select> element for the .
///
/// A instance for the current scope.
///
/// for the . If null, determines validation
/// attributes using and the .
///
/// Optional text for a default empty <option> element.
/// Expression name, relative to the current model.
///
/// A collection of objects used to populate the <select> element with
/// <optgroup> and <option> elements. If null, finds this collection at
/// ViewContext.ViewData[expression].
///
///
/// If true, includes a multiple attribute in the generated HTML. Otherwise generates a
/// single-selection <select> element.
///
///
/// An that contains the HTML attributes for the <select> element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new describing the <select> element.
///
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
///
/// See for information about how current values are determined.
///
///
TagBuilder GenerateSelect(
ViewContext viewContext,
ModelExplorer modelExplorer,
string optionLabel,
string expression,
IEnumerable selectList,
bool allowMultiple,
object htmlAttributes);
///
/// Generate a <select> element for the .
///
/// A instance for the current scope.
///
/// for the . If null, determines validation
/// attributes using and the .
///
/// Optional text for a default empty <option> element.
/// Expression name, relative to the current model.
///
/// A collection of objects used to populate the <select> element with
/// <optgroup> and <option> elements. If null, finds this collection at
/// ViewContext.ViewData[expression].
///
///
/// An containing values for <option> elements to select. If
/// null, selects <option> elements based on values in
/// .
///
///
/// If true, includes a multiple attribute in the generated HTML. Otherwise generates a
/// single-selection <select> element.
///
///
/// An that contains the HTML attributes for the <select> element. Alternatively, an
/// instance containing the HTML attributes.
///
/// A new describing the <select> element.
///
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
///
/// See for information about how the
/// collection may be created.
///
///
TagBuilder GenerateSelect(
ViewContext viewContext,
ModelExplorer modelExplorer,
string optionLabel,
string expression,
IEnumerable selectList,
ICollection currentValues,
bool allowMultiple,
object htmlAttributes);
TagBuilder GenerateTextArea(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
int rows,
int columns,
object htmlAttributes);
TagBuilder GenerateTextBox(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
string format,
object htmlAttributes);
TagBuilder GenerateValidationMessage(
ViewContext viewContext,
string expression,
string message,
string tag,
object htmlAttributes);
TagBuilder GenerateValidationSummary(
ViewContext viewContext,
bool excludePropertyErrors,
string message,
string headerTag,
object htmlAttributes);
///
/// Not used directly in . Exposed publicly for use in other
/// implementations.
///
IEnumerable GetClientValidationRules(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression);
///
/// Gets the collection of current values for the given .
///
/// A instance for the current scope.
///
/// for the . If null, calculates the
/// result using .
///
/// Expression name, relative to the current model.
///
/// If true, require a collection result. Otherwise, treat result as a
/// single value.
///
///
///
/// null if no result is found. Otherwise a
/// containing current values for the given
/// .
///
///
/// Converts the result to a . If that result is an
/// type, instead converts each item in the collection and returns
/// them separately.
///
///
/// If the result or the element type is an , returns a
/// containing the integer representation of the value as well
/// as all names for that value. Otherwise returns the default
/// conversion of the value.
///
///
///
/// See for information about how the return value may be used.
///
ICollection GetCurrentValues(
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
bool allowMultiple);
}
}