当前位置: 首页>>代码示例>>C#>>正文


C# TagBuilder.WriteTo方法代码示例

本文整理汇总了C#中TagBuilder.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder.WriteTo方法的具体用法?C# TagBuilder.WriteTo怎么用?C# TagBuilder.WriteTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TagBuilder的用法示例。


在下文中一共展示了TagBuilder.WriteTo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "div";
            output.PreContent.SetHtmlContent("<ul class=\"pagination pagination-lg\">");

            var items = new StringBuilder();
            for (var i = 1; i <= TotalPages; i++)
            {
                var li = new TagBuilder("li");

                if (i == CurrentPage)
                {
                    li.AddCssClass("active");
                }

                var a = new TagBuilder("a");
                a.MergeAttribute("href", $"{Url}?page={i}&{AdditionalParameters}");
                a.MergeAttribute("title", $"Click to go to page {i}");
                a.InnerHtml.AppendHtml(i.ToString());

                li.InnerHtml.AppendHtml(a);

                var writer = new System.IO.StringWriter();
                li.WriteTo(writer, HtmlEncoder.Default);
                var s = writer.ToString();
                items.AppendLine(s);
            }
            output.Content.SetHtmlContent(items.ToString());
            output.PostContent.SetHtmlContent("</ul>");
            output.Attributes.Clear();
            output.Attributes.Add("class", "pager");
        }
开发者ID:layne1990,项目名称:candidate-assessments,代码行数:32,代码来源:BootstrapPager.cs

示例2: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            //set the tag name to a select...the attributes will carry along automatically. Otherwise grab context.AllAttributes
            output.TagName = "select";

            using (var writer = new StringWriter())
            {
                //loop through the items
                foreach (var item in SelectItems)
                {
                    //create the option
                    var option = new TagBuilder("option");

                    //set the value
                    option.MergeAttribute("value", item.Value);

                    //set the text
                    option.InnerHtml.Append(item.Text);

                    //write it to the writer
                    option.WriteTo(writer, encoder);
                }

                //now output the writer to the page
                output.Content.SetHtmlContent(writer.ToString());
            }

        }
开发者ID:dibiancoj,项目名称:ToracGolf,代码行数:28,代码来源:SelectTagHelper.cs

示例3: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (_bundleManager.Exists(Source))
            {
                var result = (await _smidgeHelper.GenerateJsUrlsAsync(Source, Debug)).ToArray();
                var currAttr = output.Attributes.ToDictionary(x => x.Name, x => x.Value);
                using (var writer = new StringWriter())
                {
                    foreach (var s in result)
                    {
                        var builder = new TagBuilder(output.TagName)
                        {
                            TagRenderMode = TagRenderMode.Normal
                        };
                        builder.MergeAttributes(currAttr);
                        builder.Attributes["src"] = s;

                        builder.WriteTo(writer, _encoder);
                    }
                    writer.Flush();
                    output.PostElement.SetContent(new HtmlString(writer.ToString()));
                }
                //This ensures the original tag is not written.
                output.TagName = null;
            }
            else
            {
                //use what is there
                output.Attributes["src"] = Source;
            }
        }
开发者ID:eByte23,项目名称:Smidge,代码行数:31,代码来源:SmidgeScriptTagHelper.cs

示例4: RenderForm

        /// <summary>
        /// This renders out the form for us
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="formAction"></param>
        /// <param name="method"></param>
        /// <param name="htmlAttributes"></param>
        /// <param name="surfaceController"></param>
        /// <param name="surfaceAction"></param>
        /// <param name="area"></param>		
        /// <param name="additionalRouteVals"></param>
        /// <returns></returns>
        /// <remarks>
        /// This code is pretty much the same as the underlying MVC code that writes out the form
        /// </remarks>
        private static MvcForm RenderForm(this IHtmlHelper htmlHelper,
                                          string formAction,
                                          FormMethod method,
                                          IDictionary<string, object> htmlAttributes,
                                          string surfaceController,
                                          string surfaceAction,
                                          string area,
                                          object additionalRouteVals = null)
        {
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary<string, object>();
            }
            //ensure that the multipart/form-data is added to the html attributes
            if (htmlAttributes.ContainsKey("enctype") == false)
            {
                htmlAttributes.Add("enctype", "multipart/form-data");
            }

            var tagBuilder = new TagBuilder("form");
            tagBuilder.MergeAttributes(htmlAttributes);
            // action is implicitly generated, so htmlAttributes take precedence.
            tagBuilder.MergeAttribute("action", formAction);
            // method is an explicit parameter, so it takes precedence over the htmlAttributes.
            tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);

            tagBuilder.TagRenderMode = TagRenderMode.StartTag;
            tagBuilder.WriteTo(htmlHelper.ViewContext.Writer, new HtmlEncoder());

            //new UmbracoForm:
            var theForm = new UmbracoForm(htmlHelper.UrlEncoder, htmlHelper.ViewContext, surfaceController, surfaceAction, area, additionalRouteVals);

            return theForm;
        }
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:49,代码来源:HtmlHelperRenderExtensions.cs

示例5: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (!string.IsNullOrWhiteSpace(ModelName) && ModelData != null)
            {
                modelContext.Initialize(ModelData);

                var script = new TagBuilder("script");
                script.Attributes.Add("model", ModelName);
                script.Attributes.Add("type", "application/json");
                if (ModelPersistent)
                {
                    script.Attributes.Add("persistent", "");
                }
                script.InnerHtml = new StringHtmlContent(jsonHelper.Serialize(ModelData).ToString());

                output.Attributes.Add("model", ModelName);
                using (var writer = new StringWriter())
                {
                    script.WriteTo(writer, new HtmlEncoder());
                    output.PreContent.SetContent(writer.ToString());
                }
            }
            else if (!string.IsNullOrWhiteSpace(Scope))
            {
                output.Attributes.Add("scope", Scope);
                modelContext.Scope(Scope);
            }

            output.Attributes.Add("name", Name);

            await base.ProcessAsync(context, output);
        }
开发者ID:tuespetre,项目名称:html-mvc-aspnet5,代码行数:32,代码来源:ViewTagHelper.cs

示例6: Script

        public static IHtmlContent Script(this IHtmlHelper helper, string contentPath)
        {
            if (string.IsNullOrWhiteSpace(contentPath))
            {
                throw new ArgumentOutOfRangeException(nameof(contentPath), contentPath, "Must not be null or whitespace");
            }

            var sb = new StringBuilder();
            var paths = Configuration == null ? new[] { contentPath } : Configuration.Scripts[contentPath];

            foreach (var path in paths)
            {
                var script = new TagBuilder("script");

                script.MergeAttribute("type", "text/javascript");
                script.MergeAttribute("src", path);

                using (var writer = new StringWriter())
                {
                    script.WriteTo(writer, HtmlEncoder.Default);
                    sb.AppendLine(writer.ToString());
                }
            }

            return new HtmlString(sb.ToString());
        }
开发者ID:cashfoley,项目名称:PartsUnlimited,代码行数:26,代码来源:ContentDeliveryNetworkExtensions.cs

示例7: BuildWidget

 public static string BuildWidget()
 {
     using (var stringWriter = new StringWriter())
     {
         var widget = new TagBuilder("div");
         widget.MergeAttribute("class", "g-recaptcha");
         widget.MergeAttribute("data-sitekey", ReCaptchaConfiguration.Instance.SiteKey);
         widget.TagRenderMode = TagRenderMode.Normal;
         widget.WriteTo(stringWriter, HtmlEncoder.Default);
         return stringWriter.ToString();
     }
 }
开发者ID:vbatrla,项目名称:ReCaptcha.NET,代码行数:12,代码来源:ReCaptchaOutputBuilder.cs

示例8: BuildScript

        public static string BuildScript(string language)
        {
            using (var stringWriter = new StringWriter())
            {
                var script = new TagBuilder("script");
                if (string.IsNullOrEmpty(language))
                {
                    script.MergeAttribute("src", "https://www.google.com/recaptcha/api.js");
                }
                else
                {
                    script.MergeAttribute("src", "https://www.google.com/recaptcha/api.js?hl=" + language);
                }

                script.MergeAttribute("async", string.Empty);
                script.MergeAttribute("defer", string.Empty);
                script.TagRenderMode = TagRenderMode.Normal;
                script.WriteTo(stringWriter, HtmlEncoder.Default);

                return stringWriter.ToString();
            }
        }
开发者ID:vbatrla,项目名称:ReCaptcha.NET,代码行数:22,代码来源:ReCaptchaOutputBuilder.cs

示例9: WriteTo_IgnoresIdAttributeCase

        public void WriteTo_IgnoresIdAttributeCase(TagRenderMode renderingMode, string expectedOutput)
        {
            // Arrange
            var tagBuilder = new TagBuilder("p");
            // An empty value id attribute should not be rendered via ToString.
            tagBuilder.Attributes.Add("ID", string.Empty);
            tagBuilder.TagRenderMode = renderingMode;

            // Act
            using (var writer = new StringWriter())
            {
                tagBuilder.WriteTo(writer, new HtmlTestEncoder());

                // Assert
                Assert.Equal(expectedOutput, writer.ToString());
            }
        }
开发者ID:phinq19,项目名称:git_example,代码行数:17,代码来源:TagBuilderTest.cs

示例10: WriteTo_IncludesInnerHtml

        public void WriteTo_IncludesInnerHtml()
        {
            // Arrange
            var tagBuilder = new TagBuilder("p");
            tagBuilder.InnerHtml.AppendHtml("<span>Hello</span>");
            tagBuilder.InnerHtml.Append(", World!");

            // Act
            using (var writer = new StringWriter())
            {
                tagBuilder.WriteTo(writer, new HtmlTestEncoder());

                // Assert
                Assert.Equal("<p><span>Hello</span>HtmlEncode[[, World!]]</p>", writer.ToString());
            }
        }
开发者ID:phinq19,项目名称:git_example,代码行数:16,代码来源:TagBuilderTest.cs

示例11: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "ul";
            output.Attributes["class"] = "pagination pagination-sm";

            if (CurrentPage == 0)
                CurrentPage = 1;

            var writer = new StringWriter();
            var encoder = new HtmlEncoder();

            var li = new TagBuilder("li");
            var a = new TagBuilder("a");
            if (CurrentPage > 10)
            {
                a.MergeAttribute("href", $"{Url}?Page={((CurrentPage - 1) / 10) * 10}{(SearchMode ? $"&SearchField={SearchField}&SearchQuery={SearchQuery}" : "")}");
                a.InnerHtml.AppendHtml("◄");
            }
            else
            {
                a.MergeAttribute("class", "disabled");
                a.InnerHtml.AppendHtml("◁");
            }

            li.InnerHtml.Append(a);
            li.WriteTo(writer, encoder);

            int firstPage = (CurrentPage - 1) / 10 * 10 + 1;
            int i;
            for (i = firstPage; i < firstPage + 10; i++)
            {
                if (i > TotalPages)
                    break;

                li = new TagBuilder("li");
                a = new TagBuilder("a");

                if (i == CurrentPage)
                {
                    li.MergeAttribute("class", "active");
                    a.MergeAttribute("href", "#");
                }
                else
                {
                    a.MergeAttribute("href", $"{Url}?Page={i}{(SearchMode ? $"&SearchField={SearchField}&SearchQuery={SearchQuery}" : "")}");
                }

                a.InnerHtml.AppendHtml(i.ToString());
                li.InnerHtml.Append(a);

                li.WriteTo(writer, encoder);
            }

            li = new TagBuilder("li");
            a = new TagBuilder("a");

            if (i < TotalPages)
            {
                a.MergeAttribute("href", $"{Url}?Page={i}{(SearchMode ? $"&SearchField={SearchField}&SearchQuery={SearchQuery}" : "")}");
                a.InnerHtml.AppendHtml("►");
            }
            else
            {
                a.MergeAttribute("class", "disabled");
                a.InnerHtml.AppendHtml("▷");
            }

            li.InnerHtml.Append(a);
            li.WriteTo(writer, encoder);

            output.Content.AppendHtml(writer.ToString());
        }
开发者ID:techl,项目名称:Core,代码行数:72,代码来源:PaginationTagHelper.cs

示例12: WriteTo_WriteEmptyAttribute_WhenValueIsNullOrEmpty

        public void WriteTo_WriteEmptyAttribute_WhenValueIsNullOrEmpty(string attributeKey, string attributeValue, string expectedOutput)
        {
            // Arrange
            var tagBuilder = new TagBuilder("p");

            // Act
            tagBuilder.Attributes.Add(attributeKey, attributeValue);

            // Assert
            using (var writer = new StringWriter())
            {
                tagBuilder.WriteTo(writer, new HtmlTestEncoder());
                Assert.Equal(expectedOutput, writer.ToString());
            }
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:15,代码来源:TagBuilderTest.cs


注:本文中的TagBuilder.WriteTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。