Beispiel #1
0
        //public static MvcHtmlString DefaultDropDownList(this HtmlHelper htmlHelper, string name)
        //{
        //    return htmlHelper.DefaultDropDownList(name, Enumerable.Empty<SelectListItem>());
        //}

        /// <summary>
        /// Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items and option label, with an initial value optional value.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <typeparam name="TProperty">The type of the value.</typeparam>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="expression">An expression that identifies the object that contains the properties to display.</param>
        /// <param name="selectList">A collection of System.Web.Mvc.SelectListItem objects that are used to populate the drop-down list.</param>
        /// <returns>An HTML select element for each property in the object that is represented by the expression.</returns>
        public static MvcHtmlString DefaultDropDownListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList)
        {
            if (selectList.IsEmpty())
            {
                return(htmlHelper.DropDownListFor(expression, selectList, MvcSelectExtensions.GetDropDownListOptionalText()));
            }

            return(htmlHelper.DropDownListFor(expression, selectList, MvcSelectExtensions.GetDropDownListOptionalText(MvcSelectExtensions.PopulatedDropDownListDefaultText)));
        }
Beispiel #2
0
        /// <summary>
        /// Returns a single-selection select element using the specified HTML helper, the name of the form field, and the specified list items, with an initial value optional value.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="name">The name of the form field to return.</param>
        /// <param name="selectList">A collection of <see cref="System.Web.Mvc.SelectListItem"/> objects that are used to populate the drop-down list.</param>
        /// <returns>An HTML select element with an option subelement for each item in the list.</returns>
        public static MvcHtmlString DefaultDropDownList(this HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> selectList)
        {
            if (selectList.IsEmpty())
            {
                return(htmlHelper.DropDownList(name, selectList, MvcSelectExtensions.GetDropDownListOptionalText()));
            }

            return(htmlHelper.DropDownList(name, selectList, MvcSelectExtensions.GetDropDownListOptionalText(MvcSelectExtensions.PopulatedDropDownListDefaultText)));
        }
Beispiel #3
0
 public static string GetDropDownListOptionalText(this System.Web.Mvc.WebViewPage view, string text = MvcSelectExtensions.EmptyDropDownListDefaultText)
 {
     return(MvcSelectExtensions.GetDropDownListOptionalText(text));
 }