// 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.Linq.Expressions; using Microsoft.AspNet.Html; namespace Microsoft.AspNet.Mvc.Rendering { /// /// Select-related extensions for and . /// public static class HtmlHelperSelectExtensions { /// /// Returns a single-selection HTML <select> element for the . /// /// The instance this method extends. /// Expression name, relative to the current model. /// A new containing the <select> element. /// /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent DropDownList(this IHtmlHelper htmlHelper, string expression) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.DropDownList(expression, selectList: null, optionLabel: null, htmlAttributes: null); } /// /// Returns a single-selection HTML <select> element for the , using the /// option label. /// /// The instance this method extends. /// Expression name, relative to the current model. /// /// The text for a default empty item. Does not include such an item if argument is null. /// /// A new containing the <select> element. /// /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent DropDownList( this IHtmlHelper htmlHelper, string expression, string optionLabel) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.DropDownList( expression, selectList: null, optionLabel: optionLabel, htmlAttributes: null); } /// /// Returns a single-selection HTML <select> element for the , using the /// specified list items. /// /// The instance this method extends. /// Expression name, relative to the current model. /// /// A collection of objects used to populate the <select> element with /// <optgroup> and <option> elements. /// /// A new containing the <select> element. /// /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent DropDownList( this IHtmlHelper htmlHelper, string expression, IEnumerable selectList) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.DropDownList(expression, selectList, optionLabel: null, htmlAttributes: null); } /// /// Returns a single-selection HTML <select> element for the , using the /// specified list items and HTML attributes. /// /// The instance this method extends. /// 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. /// public static IHtmlContent DropDownList( this IHtmlHelper htmlHelper, string expression, IEnumerable selectList, object htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.DropDownList(expression, selectList, optionLabel: null, htmlAttributes: htmlAttributes); } /// /// Returns a single-selection HTML <select> element for the , using the /// specified list items and option label. /// /// The instance this method extends. /// 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. /// /// A new containing the <select> element. /// /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent DropDownList( this IHtmlHelper htmlHelper, string expression, IEnumerable selectList, string optionLabel) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.DropDownList(expression, selectList, optionLabel, htmlAttributes: null); } /// /// Returns a single-selection HTML <select> element for the , using the /// specified list items. /// /// The instance this method extends. /// An expression to be evaluated against the current model. /// /// A collection of objects used to populate the <select> element with /// <optgroup> and <option> elements. /// /// The type of the model. /// The type of the result. /// A new containing the <select> element. /// /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// public static IHtmlContent DropDownListFor( this IHtmlHelper htmlHelper, Expression> expression, IEnumerable selectList) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.DropDownListFor(expression, selectList, optionLabel: null, htmlAttributes: null); } /// /// Returns a single-selection HTML <select> element for the , using the /// specified list items and HTML attributes. /// /// The instance this method extends. /// An expression to be evaluated against 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. /// /// The type of the model. /// The type of the result. /// A new containing the <select> element. /// /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// public static IHtmlContent DropDownListFor( this IHtmlHelper htmlHelper, Expression> expression, IEnumerable selectList, object htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.DropDownListFor( expression, selectList, optionLabel: null, htmlAttributes: htmlAttributes); } /// /// Returns a single-selection HTML <select> element for the , using the /// specified list items and option label. /// /// The instance this method extends. /// An expression to be evaluated against 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. /// /// The type of the model. /// The type of the result. /// A new containing the <select> element. /// /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// public static IHtmlContent DropDownListFor( this IHtmlHelper htmlHelper, Expression> expression, IEnumerable selectList, string optionLabel) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.DropDownListFor(expression, selectList, optionLabel, htmlAttributes: null); } /// /// Returns a multi-selection <select> element for the . /// /// The instance this method extends. /// Expression name, relative to the current model. /// A new containing the <select> element. /// /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent ListBox(this IHtmlHelper htmlHelper, string expression) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.ListBox(expression, selectList: null, htmlAttributes: null); } /// /// Returns a multi-selection <select> element for the , using the /// specified list items. /// /// The instance this method extends. /// Expression name, relative to the current model. /// /// A collection of objects used to populate the <select> element with /// <optgroup> and <option> elements. /// /// A new containing the <select> element. /// /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent ListBox( this IHtmlHelper htmlHelper, string expression, IEnumerable selectList) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.ListBox(expression, selectList, htmlAttributes: null); } /// /// Returns a multi-selection <select> element for the , using the /// specified list items. /// /// The instance this method extends. /// An expression to be evaluated against the current model. /// /// A collection of objects used to populate the <select> element with /// <optgroup> and <option> elements. /// /// The type of the model. /// The type of the result. /// A new containing the <select> element. /// /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// public static IHtmlContent ListBoxFor( this IHtmlHelper htmlHelper, Expression> expression, IEnumerable selectList) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.ListBoxFor(expression, selectList, htmlAttributes: null); } } }