コード例 #1
0
        public override BootstrapElement Start(bool write = true)
        {
            if (base.Start(write) != null)
            {
                var toggleAttributes = new Dictionary <string, object>();
                toggleAttributes["data-toggle"]   = "dropdown";
                toggleAttributes["aria-haspopup"] = "true";

                if (!string.IsNullOrEmpty(FieldName))
                {
                    TagBuilder hidden = new TagBuilder("input");
                    hidden.Attributes["type"]  = "hidden";
                    hidden.Attributes["name"]  = FieldName;
                    hidden.Attributes["value"] = Convert.ToString(FieldValue);
                    _viewContext.Writer.Write(hidden.ToString(TagRenderMode.SelfClosing));
                }

                var toggle = new BootstrapButton(_viewContext, toggleAttributes)
                {
                    Text = GetValueText(FieldValue) + " "
                };
                toggle.ClassName += " dropdown-toggle";
                var caret = new BootstrapElement(_viewContext)
                {
                    TagName = "span", ClassName = "caret"
                };
                var menu = new BootstrapMenu(_viewContext, null)
                {
                    Options = Options
                };

                Add(toggle.Add(caret));
                toggle.Finish();
                Add(menu);
                return(this);
            }
            return(null);
        }
コード例 #2
0
 public override BootstrapElement Start(bool write = true)
 {
     if (null != base.Start(write))
     {
         if (Options != null)
         {
             foreach (var option in Options)
             {
                 var element = new BootstrapElement(_viewContext)
                 {
                     TagName = "li"
                 };
                 TagBuilder b = new TagBuilder("a");
                 b.Attributes["href"]       = "#";
                 b.Attributes["data-value"] = (option.Value != null) ? Convert.ToString(option.Value) : option.Text;
                 b.SetInnerText(option.Text ?? Convert.ToString(option.Value));
                 Add(element.Add(b));
             }
         }
         return(this);
     }
     return(null);
 }