Beispiel #1
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (For == null)
            {
                throw new InvalidOperationException(
                          "Missing or invalid 'for' attribute value. Specify a valid model expression for the 'for' attribute value.");
            }

            var request = new ElementRequest(new ModelMetadataAccessor(For))
            {
                Model = For.Model
            };

            var library = ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            var tagGenerator = new TagGenerator(library.TagLibrary, new ActiveProfile(), t => ViewContext.HttpContext.RequestServices.GetService(t));

            var tag = tagGenerator.Build(request, Category);

            foreach (var attribute in output.Attributes)
            {
                tag.Attr(attribute.Name, attribute.Value);
            }

            output.TagName = null;
            output.PreElement.AppendHtml(tag);
        }
Beispiel #2
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var request = new ElementRequest(new ModelMetadataAccessor(For))
            {
                Model = For.Model
            };

            var library = ViewContext.HttpContext.RequestServices.GetService<HtmlConventionLibrary>();

            var tagGenerator = new TagGenerator(library.TagLibrary, new ActiveProfile(), t => ViewContext.HttpContext.RequestServices.GetService(t));

            var tag = tagGenerator.Build(request, Category);

            foreach (var attribute in output.Attributes)
            {
                tag.Attr(attribute.Name, attribute.Value);
            }

            output.TagName = null;
            output.PreElement.AppendHtml(tag);
        }
Beispiel #3
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var request = new ElementRequest(new ModelMetadataAccessor(For))
            {
                Model = For.Model
            };

            var library = ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            var tagGenerator = new TagGenerator(library.TagLibrary, new ActiveProfile(), t => ViewContext.HttpContext.RequestServices.GetService(t));

            var tag = tagGenerator.Build(request, Category);

            foreach (var attribute in output.Attributes)
            {
                tag.Attr(attribute.Name, attribute.Value);
            }

            output.TagName = null;
            output.PreElement.AppendHtml(tag);
        }
Beispiel #4
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (For == null)
            {
                throw new InvalidOperationException(
                          "Missing or invalid 'for' attribute value. Specify a valid model expression for the 'for' attribute value.");
            }

            var request = new ElementRequest(new ModelMetadataAccessor(For))
            {
                Model = For.Model
            };

            var library = ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            var additionalServices = new object[]
            {
                For.ModelExplorer,
                ViewContext,
                new ElementName(For.Name)
            };

            object ServiceLocator(Type t) => additionalServices.FirstOrDefault(t.IsInstanceOfType) ?? ViewContext.HttpContext.RequestServices.GetService(t);

            var tagGenerator = new TagGenerator(library.TagLibrary, new ActiveProfile(), ServiceLocator);

            var tag = tagGenerator.Build(request, Category);

            foreach (var attribute in output.Attributes)
            {
                tag.Attr(attribute.Name, attribute.Value);
            }

            output.TagName = null;
            output.PreElement.AppendHtml(tag);
        }