Ejemplo n.º 1
0
        public static MvcHtmlString JQM_GroupedSelectMenu(this HtmlHelper htmlHelper, SelectMenuConfig config, List <CustomSelectListItem> values)
        {
            TagBuilder selectTag = new TagBuilder("select");

            config.IsMultiple = true;
            foreach (var item in values)
            {
                var optgroupTag = new TagBuilder("optgroup");
                optgroupTag.MergeAttribute("label", item.Text);
                foreach (var option in item.Children)
                {
                    var optionTag = new TagBuilder("option");
                    optionTag.MergeAttribute("value", item.Value);
                    optionTag.SetInnerText(item.Text);
                    if (item.Selected)
                    {
                        optionTag.MergeAttribute("selected", "true");
                    }

                    optgroupTag.InnerHtml += optionTag.ToString();
                }
                selectTag.InnerHtml += optgroupTag.ToString();
            }
            config.SetAttributes(selectTag);
            return(new MvcHtmlString(selectTag.ToString(TagRenderMode.SelfClosing)));
        }
Ejemplo n.º 2
0
        public static MvcHtmlString JQM_SelectMenu(this HtmlHelper htmlHelper, SelectMenuConfig config, MultiSelectList values)
        {
            TagBuilder selectTag = new TagBuilder("select");

            foreach (var item in values)
            {
                var optionTag = new TagBuilder("option");
                optionTag.MergeAttribute("value", item.Value);
                optionTag.SetInnerText(item.Text);
                if (item.Selected)
                {
                    optionTag.MergeAttribute("selected", "true");
                }

                selectTag.InnerHtml += optionTag.ToString();
            }
            config.SetAttributes(selectTag);
            return(new MvcHtmlString(selectTag.ToString(TagRenderMode.SelfClosing)));
        }