Esempio n. 1
0
        public static string GetClasses(ControlTagHelperOptions options, string classes, ControlTagItem item)
        {
            if (classes == null && !options.Classes[item].Any())
            {
                return(string.Empty);
            }

            if (classes == null)
            {
                return(string.Join(" ", options.Classes[item]));
            }

            if (!options.Classes[item].Any())
            {
                return(classes);
            }

            return(string.Join(" ", classes
                               .Split(' ')
                               .Union(options.Classes[item])
                               .Distinct()));
        }
Esempio n. 2
0
        public TagBuilder GenerateLabel(ViewContext viewContext, ModelMetadata modelMetadata, ControlTagHelperOptions options, string name, string classes = null, object htmlAttributes = null)
        {
            var metadata   = modelMetadata.AsMetadata();
            var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            var builder = _htmlGenerator.GenerateLabel(viewContext, modelMetadata, name, metadata.Get <DisplayName>(), htmlAttributes);

            if (metadata.Get <Required>())
            {
                builder.InnerHtml += "*";
            }

            classes = GetClasses(options, classes, ControlTagItem.Label);

            builder.AddCssClass(classes);
            return(builder);
        }
Esempio n. 3
0
        public TagBuilder GenerateHelpText(ViewContext viewContext, ModelMetadata modelMetadata, ControlTagHelperOptions options, string name, string classes = null, object htmlAttributes = null)
        {
            var metadata   = modelMetadata.AsMetadata();
            var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            var builder = new TagBuilder("div");

            classes = GetClasses(options, classes, ControlTagItem.Help);

            builder.AddCssClass(classes);
            return(builder);
        }
Esempio n. 4
0
        public TagBuilder GenerateControl(ViewContext viewContext, ModelMetadata modelMetadata, ControlTagHelperOptions options, string name, string classes = null, object htmlAttributes = null)
        {
            var metadata   = modelMetadata.AsMetadata();
            var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            var builder = _htmlGenerator.GenerateTextBox(viewContext, modelMetadata, name, modelMetadata.Model, modelMetadata.EditFormatString, htmlAttributes);

            builder.Attributes.Add("placeholder", metadata.Get <DisplayName>());
            classes = GetClasses(options, classes, ControlTagItem.Control);

            builder.AddCssClass(classes);
            return(builder);
        }
Esempio n. 5
0
        public TagBuilder GenerateContainer(ViewContext viewContext, ModelMetadata modelMetadata, ControlTagHelperOptions options, string name, string classes, string labelClasses, string controlClasses, string descriptionClasses, string helpClasses, object htmlAttributes = null)
        {
            var metadata   = modelMetadata.AsMetadata();
            var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            var builder = new TagBuilder("div");

            builder.AddCssClass(GetClasses(options, classes, ControlTagItem.Container));

            var label            = GenerateLabel(viewContext, modelMetadata, options, name, labelClasses);
            var controlContainer = GenerateControlContainer(viewContext, modelMetadata, options, name, controlClasses);
            // bootstrap
            var controlCls = string.Join(" ", (controlClasses ?? string.Empty).Split(' ').Where(x => !x.StartsWith("col-")));
            // /bootstrap
            var control     = GenerateControl(viewContext, modelMetadata, options, name, controlCls);
            var description = GenerateDescription(viewContext, modelMetadata, options, name, descriptionClasses);

            controlContainer.InnerHtml = control.ToString(TagRenderMode.SelfClosing);
            builder.InnerHtml          = label.ToString();
            builder.InnerHtml         += controlContainer.ToString();
            builder.InnerHtml         += description.ToString();

            return(builder);
        }