Пример #1
0
        public static MvcHtmlString ValueBoxForEnum <TEnum>(this HtmlHelper htmlHelper, string name, IEnumerable <TEnum> values, string optionLabel, object htmlAttributes = null)
            where TEnum : struct
        {
            var list = values.Select(e => new SelectListItem {
                Value = (e as Enum).ToString("d"), Text = e.ToString()
            });

            return(SelectExtensions.DropDownList(htmlHelper, name, list, optionLabel, htmlAttributes));
        }
Пример #2
0
        /// <summary>
        /// 适用于Value和Text是一个数字值的下拉选单(Text值和value值一致)
        /// </summary>
        /// <typeparam name="TEnum"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="name"></param>
        /// <param name="optionLabel"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        public static MvcHtmlString ValueBoxForEnumYearsAdd <TEnum>(this HtmlHelper htmlHelper,
                                                                    string name, string optionLabel, object htmlAttributes = null)
            where TEnum : struct
        {
            var values = Enum.GetValues(typeof(TEnum)).Cast <TEnum>();
            var list   = values.Select(e => new SelectListItem {
                Value = e.ToString(), Text = (e as Enum).ToString("d")
            });

            return(SelectExtensions.DropDownList(htmlHelper, name, list, optionLabel, htmlAttributes));
        }