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


C# TagBuilder类代码示例

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


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

示例1: ImageActionLink

 public static MvcHtmlString ImageActionLink(
     this HtmlHelper helper,
     string imageUrl,
     string altText,
     string actionName,
     string controllerName,
     object routeValues,
     object linkHtmlAttributes,
     object imgHtmlAttributes)
 {
     var linkAttributes = AnonymousObjectToKeyValue(linkHtmlAttributes);
     var imgAttributes = AnonymousObjectToKeyValue(imgHtmlAttributes);
     var imgBuilder = new TagBuilder("img");
     imgBuilder.MergeAttribute("src", imageUrl);
     imgBuilder.MergeAttribute("alt", altText);
     imgBuilder.MergeAttributes(imgAttributes, true);
     var urlHelper = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection);
     var linkBuilder = new TagBuilder("a");
     linkBuilder.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routeValues));
     linkBuilder.MergeAttributes(linkAttributes, true);
     var text = linkBuilder.ToString(TagRenderMode.StartTag);
     text += imgBuilder.ToString(TagRenderMode.SelfClosing);
     text += linkBuilder.ToString(TagRenderMode.EndTag);
     return MvcHtmlString.Create(text);
 }
开发者ID:KirillMehtiev,项目名称:Collective,代码行数:25,代码来源:ImageActionLinkExtention.cs

示例2: BuildWidget

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

示例3: Foo

 public static HtmlString Foo(this HtmlHelper h, string attr, string id, string tagElement)
 {
     var tBuilder = new TagBuilder(tagElement);
     tBuilder.GenerateId(attr + id);
     var c = new HtmlString(tBuilder.ToString());
     return c;
 }
开发者ID:kamaelyoung,项目名称:My-MVC-Blog,代码行数:7,代码来源:CommentHelperExtension.cs

示例4: TestTagBuilder

        /// <summary>
        /// Function to render the HTML block for the update/cancel buttons for a details edit form
        /// </summary>
        /// <param name="helper">Reference to the HTML helper class</param>
        /// <returns>HTML string for the buttons block</returns>
        public static HtmlString TestTagBuilder()
        {
            // Create the tags we need
            var div = new TagBuilder("div");
            var update = new TagBuilder("a");
            var cancel = new TagBuilder("a");

            // Center the div tag
            div.AddCssClass("details-update-button-set");

            // Set up the update submit button
            update.Attributes.Add("id", "save-button");
            update.Attributes.Add("tabindex", "0");
            update.AddCssClass("snap-button k-button k-button-icontext");
            update.SetInnerText("Update");

            // Set up the cancel button
            cancel.Attributes.Add("id", "cancel-button");
            cancel.Attributes.Add("tabindex", "0");
            cancel.AddCssClass("snap-button k-button k-button-icontext");
            cancel.SetInnerText("Cancel");

            // Set the HTML for the div and return it
            div.InnerHtml = update.ToString() + cancel.ToString();
            return new HtmlString(div.ToString());
        }
开发者ID:kendallb,项目名称:htmltags,代码行数:31,代码来源:Program.cs

示例5: Write

		internal static void Write(HierarchyNode<ContentItem> hierarchy, ContentItem selectedItem, IContentAdapterProvider adapters, ItemFilter filter, string selectableTypes, string selectableExtensions, bool excludeRoot, string target, TextWriter writer)
		{
			N2.Web.Tree.Using(hierarchy)
				.OpenTo(selectedItem)
				.Filters(filter)
				.IdProvider(n => "u" + n.Current.ID, n => "l" + n.Current.ID)
				.LinkWriter((n, w) =>
				{
					BuildLink(adapters.ResolveAdapter<NodeAdapter>(n.Current), n.Current, n.Current.Path == selectedItem.Path, target, IsSelectable(n.Current, selectableTypes, selectableExtensions)).WriteTo(w);
					if (n.Children.Count == 0 && adapters.ResolveAdapter<NodeAdapter>(n.Current).HasChildren(n.Current, filter))
					{
						var ul = new TagBuilder("ul");
						ul.AddCssClass("ajax");
						w.Write(ul.ToString(TagRenderMode.StartTag));

						var li = new TagBuilder("li");
						li.InnerHtml = "{url:" + Url.ParseTokenized("{ManagementUrl}/Content/Navigation/LoadTree.ashx")
							.AppendQuery("target", target)
							.AppendQuery(SelectionUtility.SelectedQueryKey, HttpUtility.UrlEncode(n.Current.Path))
							.AppendQuery("selectableTypes", selectableTypes)
							.AppendQuery("selectableExtensions", selectableExtensions)
							+ "}";
						w.Write(li.ToString());

						w.Write(ul.ToString(TagRenderMode.EndTag));
					}
				})
				.ExcludeRoot(excludeRoot)
				.WriteTo(writer);
		}
开发者ID:rohancragg,项目名称:n2cms,代码行数:30,代码来源:TreeUtility.cs

示例6: Script

        /// <summary>
        /// Loads a script int the view
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="configKey">configuration key value, configured in appsettings</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public static MvcHtmlString Script(this HtmlHelper htmlHelper, string filePath)
        {
            if (UseContentDeliveryNetwork)
                filePath = filePath.Replace("~", ContentUrlPrefix);

            if (string.Compare(WorkEnvironment, "Development", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                var filePathWithoutMin = filePath.Replace(".min", string.Empty);

                if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(filePathWithoutMin)))
                {
                    filePath = filePathWithoutMin;
                }
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new Exception(string.Format("Mvc3.ContentManagement: Resource not found for {0}", filePath));
            }
            else
            {
                TagBuilder tagBuilder = new TagBuilder("script");
                tagBuilder.MergeAttribute("src", UrlHelper.GenerateContentUrl(filePath, htmlHelper.ViewContext.HttpContext));
                tagBuilder.MergeAttribute("type", "text/javascript");
                return new MvcHtmlString(tagBuilder.ToString());
            }
        }
开发者ID:n2463230,项目名称:MVC4Project,代码行数:34,代码来源:StaticContentHelper.cs

示例7: InputHelper

        public static MvcHtmlString InputHelper(InputTypeHelper inputType,string name, string value, string innerScript,string classAttr, object htmlAttributes)
        {
            StringBuilder strBuilder = new StringBuilder();

            TagBuilder tagScript = new TagBuilder("script");
            tagScript.InnerHtml = "$(document).ready(function () {";
            tagScript.InnerHtml += innerScript;
            tagScript.InnerHtml += "});";
            strBuilder.Append(tagScript.ToString());

            TagBuilder tagInput = new TagBuilder("input");
            if (htmlAttributes != null)
                tagInput.MergeAttributes<string, object>(((IDictionary<string, object>)new RouteValueDictionary(htmlAttributes)));
            tagInput.MergeAttribute("type",inputType.ToString());
            tagInput.MergeAttribute("name", name);
            tagInput.MergeAttribute("id", name);

            tagInput.MergeAttribute("class", classAttr);
            if(inputType==InputTypeHelper.button)
                tagInput.MergeAttribute("title", value);
            else
                tagInput.MergeAttribute("value", value);

            strBuilder.Append(tagInput.ToString(TagRenderMode.SelfClosing));

            return MvcHtmlString.Create(strBuilder.ToString());
        }
开发者ID:vuchannguyen,项目名称:lg-py,代码行数:27,代码来源:BaseHelper.cs

示例8: BeginAlertHelper

		private static BootstrapAlert BeginAlertHelper(this HtmlHelper html, string alertClassName, string title, string id, string className)
		{
			TagBuilder tag = new TagBuilder("div");
			tag.AddOrMergeAttribute("class", "alert");

			if (!String.IsNullOrEmpty(alertClassName))
				tag.AddOrMergeAttribute("class", alertClassName);

			if (!String.IsNullOrEmpty(className))
				tag.AddOrMergeAttribute("class", className);

			if (!String.IsNullOrEmpty(id))
				tag.Attributes.Add("id", id);

			html.ViewContext.Writer.Write(tag.ToString(TagRenderMode.StartTag));

			if (!String.IsNullOrEmpty(title))
			{
				TagBuilder titleTag = new TagBuilder("h4");
				titleTag.MergeAttribute("class", "alert-heading");
				titleTag.SetInnerText(title);
				html.ViewContext.Writer.Write(titleTag.ToString(TagRenderMode.Normal));
			}

			BootstrapAlert theAlert = new BootstrapAlert(html.ViewContext);
			return theAlert;
		}
开发者ID:eleven41,项目名称:Eleven41.Web.Mvc.Bootstrap,代码行数:27,代码来源:AlertExtensions.cs

示例9: ContentZone

        public IHtmlContent ContentZone(dynamic Display, dynamic Shape)
        {
            var htmlContents = new List<IHtmlContent>();

            var shapes = ((IEnumerable<dynamic>)Shape);
            var tabbed = shapes.GroupBy(x => (string)x.Metadata.Tab);

            if (tabbed.Count() > 1)
            {
                foreach (var tab in tabbed)
                {
                    var tabName = String.IsNullOrWhiteSpace(tab.Key) ? "Content" : tab.Key;
                    var tabBuilder = new TagBuilder("div");
                    tabBuilder.Attributes["id"] = "tab-" + tabName.HtmlClassify();
                    tabBuilder.Attributes["data-tab"] = tabName;
                    foreach (var item in tab)
                    {
                        tabBuilder.InnerHtml.AppendHtml(Display(item));
                    }
                    htmlContents.Add(tabBuilder);
                }
            }
            else
            {
                foreach (var item in tabbed.First())
                {
                    htmlContents.Add(Display(item));
                }
            }

            // TODO: Replace by HtmlContentBuilder when available
            var combined = new DisplayHelper.Combined(htmlContents);

            return combined;
        }
开发者ID:geertdoornbos,项目名称:Orchard2,代码行数:35,代码来源:ZoneShapes.cs

示例10: ClearDiv

 public static string ClearDiv()
 {
     var myClearDiv = new TagBuilder("div");
     myClearDiv.MergeAttribute("class", "clear");
     myClearDiv.InnerHtml = "&nbsp;";
     return myClearDiv.ToString();
 }
开发者ID:henryksarat,项目名称:Have-A-Voice,代码行数:7,代码来源:SharedStyleHelper.cs

示例11: PageLinks

 public static MvcHtmlString PageLinks(
                                       this HtmlHelper html,
                                       PagingInfo info,
                                       Func<int, string> url
                                       )
 {
     StringBuilder sb = new StringBuilder();
     for (int i = 1; i <= info.TotalPages; i++)
     {
         TagBuilder tag = null;
         if (i == info.CurrentPage)
         {
             tag = new TagBuilder("span");
             tag.AddCssClass("selected");
         }
         else
         {
             tag = new TagBuilder("a");
             tag.MergeAttribute("href", url(i));
         }
         tag.InnerHtml = i.ToString(CultureInfo.InvariantCulture);
         sb.Append(tag.ToString());
     }
     return MvcHtmlString.Create(sb.ToString());
 }
开发者ID:wangning81,项目名称:Bookit,代码行数:25,代码来源:PagingHelper.cs

示例12: CheckBoxList

        public static MvcHtmlString CheckBoxList(this HtmlHelper htmlHelper, string name, MultiSelectList listInfo, IDictionary<string, object> htmlAttributes)
        {
            if (String.IsNullOrEmpty(name))
                throw new ArgumentException("The argument must have a value", "name");
            if (listInfo == null)
                throw new ArgumentNullException("listInfo");
            if (listInfo.Count() < 1)
                throw new ArgumentException("The list must contain at least one value", "listInfo");

            StringBuilder sb = new StringBuilder();

            foreach (SelectListItem info in listInfo)
            {
                TagBuilder builder = new TagBuilder("input");
                if (info.Selected) builder.MergeAttribute("checked", "checked");
                builder.MergeAttributes<string, object>(htmlAttributes);
                builder.MergeAttribute("type", "checkbox");
                builder.MergeAttribute("value", info.Value);
                builder.MergeAttribute("name", name);
                builder.InnerHtml = info.Text;
                sb.Append(builder.ToString(TagRenderMode.Normal));
                sb.Append("<br />");
            }
            return MvcHtmlString.Create(sb.ToString());
        }
开发者ID:anathan1,项目名称:ZergScheduler,代码行数:25,代码来源:HtmlHelpers.cs

示例13: PagedListGoToPageForm

        ///<summary>
        /// Displays a configurable "Go To Page:" form for instances of PagedList.
        ///</summary>
        ///<param name="html">This method is meant to hook off HtmlHelper as an extension method.</param>
        ///<param name="list">The PagedList to use as the data source.</param>
        ///<param name="formAction">The URL this form should submit the GET request to.</param>
        ///<param name="options">Formatting options.</param>
        ///<returns>Outputs the "Go To Page:" form HTML.</returns>
        public static MvcHtmlString PagedListGoToPageForm(this System.Web.Mvc.HtmlHelper html,
		                                         IPagedList list,
		                                         string formAction,
		                                         GoToFormRenderOptions options)
        {
            var form = new TagBuilder("form");
            form.AddCssClass("PagedList-goToPage");
            form.Attributes.Add("action", formAction);
            form.Attributes.Add("method", "get");

            var fieldset = new TagBuilder("fieldset");

            var label = new TagBuilder("label");
            label.Attributes.Add("for", options.InputFieldName);
            label.SetInnerText(options.LabelFormat);

            var input = new TagBuilder("input");
            input.Attributes.Add("type", options.InputFieldType);
            input.Attributes.Add("name", options.InputFieldName);
            input.Attributes.Add("value", list.PageNumber.ToString());

            var submit = new TagBuilder("input");
            submit.Attributes.Add("type", "submit");
            submit.Attributes.Add("value", options.SubmitButtonFormat);

            fieldset.InnerHtml = label.ToString();
            fieldset.InnerHtml += input.ToString(TagRenderMode.SelfClosing);
            fieldset.InnerHtml += submit.ToString(TagRenderMode.SelfClosing);
            form.InnerHtml = fieldset.ToString();
            return new MvcHtmlString(form.ToString());
        }
开发者ID:scarney81,项目名称:PagedList,代码行数:39,代码来源:HtmlHelper.cs

示例14: GetGoogleMapCanvas

 /// <summary>
 /// Get Google Maps Canvas Tag
 /// </summary>
 /// <returns></returns>
 private static string GetGoogleMapCanvas()
 {
     var canvasBuilder = new TagBuilder("div");
     canvasBuilder.MergeAttribute("id", "map_canvas");
     canvasBuilder.MergeAttribute("style", @"height: 500px");
     return "\n" + canvasBuilder.ToString();
 }
开发者ID:vlaz09,项目名称:AspGoogleMapApi,代码行数:11,代码来源:GoogleMapHelper.cs

示例15: Css

        public static MvcHtmlString Css(this HtmlHelper helper, string file, string mediaType)
        {
            if (String.IsNullOrEmpty(file))
            {
                throw new ArgumentException(MvcResources.Common_NullOrEmpty, "file");
            }

            string src;
            if (ScriptExtensions.IsRelativeToDefaultPath(file))
            {
                src = "~/Content/" + file;
            }
            else
            {
                src = file;
            }

            TagBuilder linkTag = new TagBuilder("link");
            linkTag.MergeAttribute("type", "text/css");
            linkTag.MergeAttribute("rel", "stylesheet");
            if (mediaType != null)
            {
                linkTag.MergeAttribute("media", mediaType);
            }
            linkTag.MergeAttribute("href", UrlHelper.GenerateContentUrl(src, helper.ViewContext.HttpContext));
            return MvcHtmlString.Create(linkTag.ToString(TagRenderMode.SelfClosing));
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:27,代码来源:CssExtensions.cs


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