Exemple #1
0
        public TControl Begin()
        {
            if (_begun)
            {
                throw new Exception("Already called Begin");
            }

            string name = Context.Name;
            string id   = Context.Id;

            var div = new HtmlTagBuilder("div");

            if (!string.IsNullOrWhiteSpace(name))
            {
                div.Attributes.Add("data-container-for", name);
            }
            if (!string.IsNullOrWhiteSpace(id))
            {
                div.Attributes.Add("data-group", id);
            }
            if (Context.IsHidden)
            {
                div.Attributes.Add("style", "display: none;");
            }
            if (Context.IsInvisible)
            {
                div.AddCssClass("invisible");
            }

            div.AddCssClass("form-group");
            div.AddCssClass("has-feedback");

            var context = HtmlHelper.ViewContext;

            context.Writer.Write(div.ToString(TagRenderMode.StartTag));

            string header = Context.Header;

            if (header != null)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    context.Writer.Write("<label>");
                }
                else
                {
                    context.Writer.Write("<label for='" + name + "'>");
                }
                context.Writer.Write(header + "</label>");
                if (!string.IsNullOrWhiteSpace(name))
                {
                    context.Writer.Write("<span class='field-validation-valid' data-valmsg-for='" + name + "' data-valmsg-replace='true'></span>");
                }
            }
            string description = Context.Description;

            if (!string.IsNullOrWhiteSpace(description))
            {
                context.Writer.Write("<div class='help-block'>" + description + "</div>");
            }

            var tag = new HtmlTagBuilder(TagType);

            tag.MergeAttributes(Context.HtmlAttributes);
            tag.MergeIfAttribute("readonly", "readonly", Context.IsReadOnly);
            tag.MergeIfAttribute("disabled", "disabled", Context.IsDisabled);
            context.Writer.Write(tag.ToString(TagRenderMode.StartTag));
            _begun = true;
            return((TControl)this);
        }