Class() public method

public Class ( string value ) : HtmlTag
value string
return HtmlTag
Ejemplo n.º 1
0
        public static MvcHtmlString FormGroup(this HtmlHelper html, Context context, string controlId, MvcHtmlString label, MvcHtmlString value)
        {
            if (context.FormGroupStyle == FormGroupStyle.None)
            {
                return(value);
            }

            var form = context is LineBase ? ((LineBase)context).FormGroupHtmlProps : null;

            var formSize = context.FormGroupSizeCss;

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div").Class("form-group").Class(formSize).Attrs(form)))
            {
                var lbl = new HtmlTag("label").Attr("for", controlId).InnerHtml(label);

                if (context.FormGroupStyle == FormGroupStyle.SrOnly)
                {
                    lbl.Class("sr-only");
                }
                else if (context.FormGroupStyle == FormGroupStyle.LabelColumns)
                {
                    lbl.Class("control-label").Class(context.LabelColumns.ToString());
                }

                lbl.Attrs(context is LineBase ? ((LineBase)context).LabelHtmlProps : null);

                if (context.FormGroupStyle != FormGroupStyle.BasicDown)
                {
                    sb.AddLine(lbl);
                }

                using (context.FormGroupStyle == FormGroupStyle.LabelColumns ? sb.SurroundLine(new HtmlTag("div").Class(context.ValueColumns.ToString())) : null)
                {
                    sb.AddLine(value);
                }

                if (context.FormGroupStyle == FormGroupStyle.BasicDown)
                {
                    sb.AddLine(lbl);
                }
            }

            return(sb.ToHtml());
        }